Skip to content

Commit 2ff2d88

Browse files
authored
[supervisor-frontend] only wait supervisor close in debug workspace (#16700)
* [supervisor-frontend] only wait supervisor close in debug workspace * [supervisor-frontend] add workspace closed condition
1 parent 1faf496 commit 2ff2d88

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

components/supervisor/frontend/src/ide/supervisor-service-client.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,20 @@ export class SupervisorServiceClient {
2525
readonly ideReady = this.supervisorReady.then(() => this.checkReady("ide"));
2626
readonly contentReady = Promise.all([this.supervisorReady]).then(() => this.checkReady("content"));
2727
readonly getWorkspaceInfoPromise = this.supervisorReady.then(() => this.getWorkspaceInfo());
28-
readonly supervisorWillShutdown = this.supervisorReady.then(() => this.checkWillShutdown());
28+
private _supervisorWillShutdown: Promise<void> | undefined;
2929

3030
private constructor() {}
3131

32+
public get supervisorWillShutdown() {
33+
if (!this._supervisorWillShutdown) {
34+
this._supervisorWillShutdown = this.supervisorReady.then(() => this.checkWillShutdown());
35+
}
36+
return this._supervisorWillShutdown;
37+
}
38+
3239
private async checkWillShutdown(delay = false): Promise<void> {
3340
if (delay) {
34-
await new Promise(resolve => setTimeout(resolve, 1000));
41+
await new Promise((resolve) => setTimeout(resolve, 1000));
3542
}
3643
try {
3744
const wsSupervisorStatusUrl = GitpodHostUrl.fromWorkspaceUrl(window.location.href).with((url) => {
@@ -49,7 +56,11 @@ export class SupervisorServiceClient {
4956
}
5057
if (response.status === 502) {
5158
// bad gateway, supervisor is gone
52-
return
59+
return;
60+
}
61+
if (response.status === 302 && response.headers.get("location")?.includes("/start/")) {
62+
// redirect to start page, workspace is closed
63+
return;
5364
}
5465
console.debug(
5566
`failed to check whether is about to shutdown, trying again...`,
@@ -64,7 +75,7 @@ export class SupervisorServiceClient {
6475
await this.checkWillShutdown(true);
6576
}
6677

67-
private async checkReady(kind: "content" | "ide" | "supervisor" , delay?: boolean): Promise<any> {
78+
private async checkReady(kind: "content" | "ide" | "supervisor", delay?: boolean): Promise<any> {
6879
if (delay) {
6980
await new Promise((resolve) => setTimeout(resolve, 1000));
7081
}

0 commit comments

Comments
 (0)