Skip to content

Commit a00f210

Browse files
svenefftingeroboquat
authored andcommitted
[server] maintain workspace instance state
get closer to workspace instance state reflects actual state in cluster.
1 parent 32ef4d5 commit a00f210

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

components/server/src/workspace/workspace-starter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,12 +522,15 @@ export class WorkspaceStarter {
522522
}
523523
} catch (err) {
524524
increaseFailedInstanceStartCounter("startOnClusterFailed");
525+
await this.failInstanceStart({ span }, err, workspace, instance);
525526
throw err;
526527
}
527528

528529
if (!resp) {
529530
increaseFailedInstanceStartCounter("clusterSelectionFailed");
530-
throw new Error("cannot start a workspace because no workspace clusters are available");
531+
const err = new Error("cannot start a workspace because no workspace clusters are available");
532+
await this.failInstanceStart({ span }, err, workspace, instance);
533+
throw err;
531534
}
532535
increaseSuccessfulInstanceStartCounter(retries);
533536

@@ -570,9 +573,6 @@ export class WorkspaceStarter {
570573

571574
return { instanceID: instance.id, workspaceURL: resp.url };
572575
} catch (err) {
573-
TraceContext.setError({ span }, err);
574-
await this.failInstanceStart({ span }, err, workspace, instance);
575-
576576
if (rethrow) {
577577
throw err;
578578
} else {

components/ws-manager-bridge/src/bridge.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,15 @@ export class WorkspaceManagerBridge implements Disposable {
346346
}
347347

348348
instance.status.phase = "running";
349+
// let's check if the state is inconsistent and be loud if it is.
350+
if (instance.stoppedTime || instance.stoppingTime) {
351+
log.error("Resetting already stopped workspace to running.", {
352+
instanceId: instance.id,
353+
stoppedTime: instance.stoppedTime,
354+
});
355+
instance.stoppedTime = undefined;
356+
instance.stoppingTime = undefined;
357+
}
349358
break;
350359
case WorkspacePhase.INTERRUPTED:
351360
instance.status.phase = "interrupted";

0 commit comments

Comments
 (0)