@@ -51,7 +51,6 @@ import {
51
51
WorkspaceInstanceStatus ,
52
52
WorkspaceProbeContext ,
53
53
Permission ,
54
- HeadlessWorkspaceEvent ,
55
54
HeadlessWorkspaceEventType ,
56
55
DisposableCollection ,
57
56
AdditionalContentContext ,
@@ -718,28 +717,39 @@ export class WorkspaceStarter {
718
717
await this . messageBus . notifyOnInstanceUpdate ( workspace . ownerId , instance ) ;
719
718
720
719
// If we just attempted to start a workspace for a prebuild - and that failed, we have to fail the prebuild itself.
720
+ await this . failPrebuildWorkspace ( { span } , err , workspace ) ;
721
+ } catch ( err ) {
722
+ TraceContext . setError ( { span } , err ) ;
723
+ log . error (
724
+ { workspaceId : workspace . id , instanceId : instance . id , userId : workspace . ownerId } ,
725
+ "cannot properly fail workspace instance during start" ,
726
+ err ,
727
+ ) ;
728
+ } finally {
729
+ span . finish ( ) ;
730
+ }
731
+ }
732
+
733
+ protected async failPrebuildWorkspace ( ctx : TraceContext , err : Error , workspace : Workspace ) {
734
+ const span = TraceContext . startSpan ( "failInstanceStart" , ctx ) ;
735
+ try {
721
736
if ( workspace . type === "prebuild" ) {
722
737
const prebuild = await this . workspaceDb . trace ( { span } ) . findPrebuildByWorkspaceID ( workspace . id ) ;
723
738
if ( prebuild && prebuild . state !== "failed" ) {
724
739
prebuild . state = "failed" ;
725
740
prebuild . error = err . toString ( ) ;
726
741
727
742
await this . workspaceDb . trace ( { span } ) . storePrebuiltWorkspace ( prebuild ) ;
728
- await this . messageBus . notifyHeadlessUpdate ( { span } , workspace . ownerId , workspace . id , <
729
- HeadlessWorkspaceEvent
730
- > {
743
+ await this . messageBus . notifyHeadlessUpdate ( { span } , workspace . ownerId , workspace . id , {
731
744
type : HeadlessWorkspaceEventType . Failed ,
732
- // TODO: `workspaceID: workspace.id` not needed here? (found in ee/src/prebuilds/prebuild-queue-maintainer.ts and ee/src/bridge.ts)
745
+ workspaceID : workspace . id , // required in prebuild-queue-maintainer.ts
746
+ text : "" ,
733
747
} ) ;
734
748
}
735
749
}
736
750
} catch ( err ) {
737
751
TraceContext . setError ( { span } , err ) ;
738
- log . error (
739
- { workspaceId : workspace . id , instanceId : instance . id , userId : workspace . ownerId } ,
740
- "cannot properly fail workspace instance during start" ,
741
- err ,
742
- ) ;
752
+ throw err ;
743
753
} finally {
744
754
span . finish ( ) ;
745
755
}
@@ -1286,6 +1296,11 @@ export class WorkspaceStarter {
1286
1296
stoppedTime : now ,
1287
1297
stoppingTime : now ,
1288
1298
} ) ;
1299
+
1300
+ // Mark the PrebuildWorkspace as failed
1301
+ await this . failPrebuildWorkspace ( { span } , err , workspace ) ;
1302
+
1303
+ // Push updated workspace instance over messagebus
1289
1304
await this . messageBus . notifyOnInstanceUpdate ( workspace . ownerId , instance ) ;
1290
1305
1291
1306
TraceContext . setError ( { span } , err ) ;
@@ -1419,14 +1434,16 @@ export class WorkspaceStarter {
1419
1434
1420
1435
if ( workspace . config . coreDump ?. enabled ) {
1421
1436
// default core dump size is 262144 blocks (if blocksize is 4096)
1422
- const defaultLimit :number = 1073741824 ;
1437
+ const defaultLimit : number = 1073741824 ;
1423
1438
1424
1439
const rLimitCore = new EnvironmentVariable ( ) ;
1425
1440
rLimitCore . setName ( "GITPOD_RLIMIT_CORE" ) ;
1426
- rLimitCore . setValue ( JSON . stringify ( {
1427
- softLimit : workspace . config . coreDump ?. softLimit || defaultLimit ,
1428
- hardLimit : workspace . config . coreDump ?. hardLimit || defaultLimit ,
1429
- } ) ) ;
1441
+ rLimitCore . setValue (
1442
+ JSON . stringify ( {
1443
+ softLimit : workspace . config . coreDump ?. softLimit || defaultLimit ,
1444
+ hardLimit : workspace . config . coreDump ?. hardLimit || defaultLimit ,
1445
+ } ) ,
1446
+ ) ;
1430
1447
envvars . push ( rLimitCore ) ;
1431
1448
}
1432
1449
0 commit comments