Skip to content

Commit 3021de1

Browse files
committed
[server] Allow restarting workspaces with forceDefaultImage=true even when another instance is already running
Fixes #3777
1 parent b92b12d commit 3021de1

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

components/server/src/workspace/gitpod-server-impl.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,15 +396,16 @@ export class GitpodServerImpl<Client extends GitpodClient, Server extends Gitpod
396396
const user = this.checkAndBlockUser();
397397
await this.checkTermsAcceptance();
398398

399-
log.info({ userId: user.id, workspaceId }, 'startWorkspace');
399+
const logCtx = { userId: user.id, workspaceId };
400+
log.info(logCtx, 'startWorkspace');
400401

401402
const mayStartPromise = this.mayStartWorkspace({ span }, user, this.workspaceDb.trace({ span }).findRegularRunningInstances(user.id));
402403
const workspace = await this.internalGetWorkspace(workspaceId, this.workspaceDb.trace({ span }));
403404
await this.guardAccess({ kind: "workspace", subject: workspace }, "get");
404405

405406
const runningInstance = await this.workspaceDb.trace({ span }).findRunningInstance(workspace.id);
406-
if (runningInstance) {
407-
// We already have a running workspace.
407+
if (runningInstance && !options.forceDefaultImage) {
408+
// We already have a running workspace, and we're not forcing the default image.
408409
// Note: ownership doesn't matter here as this is basically a noop. It's not StartWorkspace's concern
409410
// to guard workspace access - just to prevent non-owners from starting workspaces.
410411

@@ -433,6 +434,14 @@ export class GitpodServerImpl<Client extends GitpodClient, Server extends Gitpod
433434

434435
await mayStartPromise;
435436

437+
if (runningInstance) {
438+
// We already have a running workspace. This may happen if we're forcing the default image.
439+
// In that case, we stop the previous first.
440+
await this.internalStopWorkspace({ span }, workspaceId, workspace.ownerId).catch(err => {
441+
log.error(logCtx, "stopWorkspace error: ", err);
442+
});
443+
}
444+
436445
// at this point we're about to actually start a new workspace
437446
return await this.workspaceStarter.startWorkspace({ span }, workspace, user, await envVars, {
438447
forceDefaultImage: !!options.forceDefaultImage

0 commit comments

Comments
 (0)