@@ -396,15 +396,16 @@ export class GitpodServerImpl<Client extends GitpodClient, Server extends Gitpod
396
396
const user = this . checkAndBlockUser ( ) ;
397
397
await this . checkTermsAcceptance ( ) ;
398
398
399
- log . info ( { userId : user . id , workspaceId } , 'startWorkspace' ) ;
399
+ const logCtx = { userId : user . id , workspaceId } ;
400
+ log . info ( logCtx , 'startWorkspace' ) ;
400
401
401
402
const mayStartPromise = this . mayStartWorkspace ( { span } , user , this . workspaceDb . trace ( { span } ) . findRegularRunningInstances ( user . id ) ) ;
402
403
const workspace = await this . internalGetWorkspace ( workspaceId , this . workspaceDb . trace ( { span } ) ) ;
403
404
await this . guardAccess ( { kind : "workspace" , subject : workspace } , "get" ) ;
404
405
405
406
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 .
408
409
// Note: ownership doesn't matter here as this is basically a noop. It's not StartWorkspace's concern
409
410
// to guard workspace access - just to prevent non-owners from starting workspaces.
410
411
@@ -433,6 +434,14 @@ export class GitpodServerImpl<Client extends GitpodClient, Server extends Gitpod
433
434
434
435
await mayStartPromise ;
435
436
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
+
436
445
// at this point we're about to actually start a new workspace
437
446
return await this . workspaceStarter . startWorkspace ( { span } , workspace , user , await envVars , {
438
447
forceDefaultImage : ! ! options . forceDefaultImage
0 commit comments