@@ -308,11 +308,13 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
308
308
log . debug ( { userId : this . userID } , "initializeClient" ) ;
309
309
310
310
this . listenForWorkspaceInstanceUpdates ( ) ;
311
-
312
311
this . listenForPrebuildUpdates ( ) . catch ( ( err ) => log . error ( "error registering for prebuild updates" , err ) ) ;
313
312
}
314
313
315
314
private async listenForPrebuildUpdates ( ) {
315
+ if ( ! this . client ) {
316
+ return ;
317
+ }
316
318
// 'registering for prebuild updates for all projects this user has access to
317
319
const projects = await this . getAccessibleProjects ( ) ;
318
320
@@ -328,8 +330,10 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
328
330
ctx ,
329
331
) ;
330
332
331
- for ( const projectId of projects ) {
332
- this . disposables . pushAll ( [ this . subscriber . listenForPrebuildUpdates ( projectId , handler ) ] ) ;
333
+ if ( ! this . disposables . disposed ) {
334
+ for ( const projectId of projects ) {
335
+ this . disposables . push ( this . subscriber . listenForPrebuildUpdates ( projectId , handler ) ) ;
336
+ }
333
337
}
334
338
335
339
// TODO(at) we need to keep the list of accessible project up to date
@@ -451,7 +455,8 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
451
455
// Once we have those, we should remove this.
452
456
//
453
457
const ws = await this . workspaceDb . trace ( ctx ) . findById ( workspaceID ) ;
454
- if ( ! ! ws && ! ! wsi && ws . ownerId !== this . userID ) {
458
+ const relatedPrebuildFound = ! ! ws && ! ! wsi && ws . ownerId !== this . userID ;
459
+ if ( relatedPrebuildFound && ! this . disposables . disposed ) {
455
460
const resetListenerFromRedis = this . subscriber . listenForWorkspaceInstanceUpdates (
456
461
ws . ownerId ,
457
462
( ctx , instance ) => {
@@ -2968,19 +2973,23 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
2968
2973
}
2969
2974
2970
2975
const project = await this . projectsService . createProject ( params , user ) ;
2976
+
2971
2977
// update client registration for the logged in user
2972
- const prebuildUpdateHandler = ( ctx : TraceContext , update : PrebuildWithStatus ) =>
2973
- TraceContext . withSpan (
2974
- "forwardPrebuildUpdateToClient" ,
2975
- ( ctx ) => {
2976
- traceClientMetadata ( ctx , this . clientMetadata ) ;
2977
- TraceContext . setJsonRPCMetadata ( ctx , "onPrebuildUpdate" ) ;
2978
+ if ( this . client && ! this . disposables . disposed ) {
2979
+ const prebuildUpdateHandler = ( ctx : TraceContext , update : PrebuildWithStatus ) =>
2980
+ TraceContext . withSpan (
2981
+ "forwardPrebuildUpdateToClient" ,
2982
+ ( ctx ) => {
2983
+ traceClientMetadata ( ctx , this . clientMetadata ) ;
2984
+ TraceContext . setJsonRPCMetadata ( ctx , "onPrebuildUpdate" ) ;
2985
+
2986
+ this . client ?. onPrebuildUpdate ( update ) ;
2987
+ } ,
2988
+ ctx ,
2989
+ ) ;
2978
2990
2979
- this . client ?. onPrebuildUpdate ( update ) ;
2980
- } ,
2981
- ctx ,
2982
- ) ;
2983
- this . disposables . pushAll ( [ this . subscriber . listenForPrebuildUpdates ( project . id , prebuildUpdateHandler ) ] ) ;
2991
+ this . disposables . pushAll ( [ this . subscriber . listenForPrebuildUpdates ( project . id , prebuildUpdateHandler ) ] ) ;
2992
+ }
2984
2993
2985
2994
return project ;
2986
2995
}
0 commit comments