@@ -310,11 +310,13 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
310
310
log . debug ( { userId : this . userID } , "initializeClient" ) ;
311
311
312
312
this . listenForWorkspaceInstanceUpdates ( ) ;
313
-
314
313
this . listenForPrebuildUpdates ( ) . catch ( ( err ) => log . error ( "error registering for prebuild updates" , err ) ) ;
315
314
}
316
315
317
316
private async listenForPrebuildUpdates ( ) {
317
+ if ( ! this . client ) {
318
+ return ;
319
+ }
318
320
// 'registering for prebuild updates for all projects this user has access to
319
321
const projects = await this . getAccessibleProjects ( ) ;
320
322
@@ -330,8 +332,10 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
330
332
ctx ,
331
333
) ;
332
334
333
- for ( const projectId of projects ) {
334
- this . disposables . pushAll ( [ this . subscriber . listenForPrebuildUpdates ( projectId , handler ) ] ) ;
335
+ if ( ! this . disposables . disposed ) {
336
+ for ( const projectId of projects ) {
337
+ this . disposables . push ( this . subscriber . listenForPrebuildUpdates ( projectId , handler ) ) ;
338
+ }
335
339
}
336
340
337
341
// TODO(at) we need to keep the list of accessible project up to date
@@ -453,7 +457,8 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
453
457
// Once we have those, we should remove this.
454
458
//
455
459
const ws = await this . workspaceDb . trace ( ctx ) . findById ( workspaceID ) ;
456
- if ( ! ! ws && ! ! wsi && ws . ownerId !== this . userID ) {
460
+ const relatedPrebuildFound = ! ! ws && ! ! wsi && ws . ownerId !== this . userID ;
461
+ if ( relatedPrebuildFound && ! this . disposables . disposed ) {
457
462
const resetListenerFromRedis = this . subscriber . listenForWorkspaceInstanceUpdates (
458
463
ws . ownerId ,
459
464
( ctx , instance ) => {
@@ -3046,19 +3051,23 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
3046
3051
}
3047
3052
3048
3053
const project = await this . projectsService . createProject ( params , user ) ;
3054
+
3049
3055
// update client registration for the logged in user
3050
- const prebuildUpdateHandler = ( ctx : TraceContext , update : PrebuildWithStatus ) =>
3051
- TraceContext . withSpan (
3052
- "forwardPrebuildUpdateToClient" ,
3053
- ( ctx ) => {
3054
- traceClientMetadata ( ctx , this . clientMetadata ) ;
3055
- TraceContext . setJsonRPCMetadata ( ctx , "onPrebuildUpdate" ) ;
3056
+ if ( this . client && ! this . disposables . disposed ) {
3057
+ const prebuildUpdateHandler = ( ctx : TraceContext , update : PrebuildWithStatus ) =>
3058
+ TraceContext . withSpan (
3059
+ "forwardPrebuildUpdateToClient" ,
3060
+ ( ctx ) => {
3061
+ traceClientMetadata ( ctx , this . clientMetadata ) ;
3062
+ TraceContext . setJsonRPCMetadata ( ctx , "onPrebuildUpdate" ) ;
3063
+
3064
+ this . client ?. onPrebuildUpdate ( update ) ;
3065
+ } ,
3066
+ ctx ,
3067
+ ) ;
3056
3068
3057
- this . client ?. onPrebuildUpdate ( update ) ;
3058
- } ,
3059
- ctx ,
3060
- ) ;
3061
- this . disposables . pushAll ( [ this . subscriber . listenForPrebuildUpdates ( project . id , prebuildUpdateHandler ) ] ) ;
3069
+ this . disposables . pushAll ( [ this . subscriber . listenForPrebuildUpdates ( project . id , prebuildUpdateHandler ) ] ) ;
3070
+ }
3062
3071
3063
3072
return project ;
3064
3073
}
0 commit comments