@@ -17,17 +17,17 @@ import { timeout } from './common/async';
1717import { MetricsReporter , getConnectMetricsInterceptor , getGrpcMetricsInterceptor } from './metrics' ;
1818
1919function isTelemetryEnabled ( ) : boolean {
20- const TELEMETRY_CONFIG_ID = 'telemetry' ;
21- const TELEMETRY_CONFIG_ENABLED_ID = 'enableTelemetry' ;
20+ const TELEMETRY_CONFIG_ID = 'telemetry' ;
21+ const TELEMETRY_CONFIG_ENABLED_ID = 'enableTelemetry' ;
2222
23- if ( vscode . env . isTelemetryEnabled !== undefined ) {
24- return vscode . env . isTelemetryEnabled ? true : false ;
25- }
23+ if ( vscode . env . isTelemetryEnabled !== undefined ) {
24+ return vscode . env . isTelemetryEnabled ? true : false ;
25+ }
2626
27- // We use the old and new setting to determine the telemetry level as we must respect both
28- const config = vscode . workspace . getConfiguration ( TELEMETRY_CONFIG_ID ) ;
29- const enabled = config . get < boolean > ( TELEMETRY_CONFIG_ENABLED_ID ) ;
30- return ! ! enabled ;
27+ // We use the old and new setting to determine the telemetry level as we must respect both
28+ const config = vscode . workspace . getConfiguration ( TELEMETRY_CONFIG_ID ) ;
29+ const enabled = config . get < boolean > ( TELEMETRY_CONFIG_ENABLED_ID ) ;
30+ return ! ! enabled ;
3131}
3232
3333export class GitpodPublicApi extends Disposable {
@@ -119,26 +119,36 @@ export class GitpodPublicApi extends Disposable {
119119 this . _streamWorkspaceStatus ( workspaceId ) ;
120120 }
121121
122+ private _stopTimer : NodeJS . Timeout | undefined ;
122123 private _streamWorkspaceStatus ( workspaceId : string ) {
123124 const call = this . grpcWorkspaceClient . streamWorkspaceStatus ( { workspaceId } , this . grpcMetadata ) ;
124125 call . on ( 'data' , ( res ) => {
125126 this . _onWorkspaceStatusUpdate . fire ( res . result ! ) ;
126127 } ) ;
127128 call . on ( 'end' , async ( ) => {
128- await timeout ( 2000 ) ;
129+ clearTimeout ( this . _stopTimer ) ;
129130
130131 if ( this . isDisposed ) { return ; }
131132
132- this . logger . trace ( `streamWorkspaceStatus stream ended, retrying ...` ) ;
133+ this . logger . trace ( `streamWorkspaceStatus stream ended` ) ;
134+
135+ await timeout ( 1000 ) ;
133136 this . _streamWorkspaceStatus ( workspaceId ) ;
134137 } ) ;
135138 call . on ( 'error' , ( err ) => {
136139 this . logger . trace ( `Error in streamWorkspaceStatus` , err ) ;
137140 } ) ;
141+
142+ // force reconnect after 7m to avoid unexpected 10m reconnection (internal error)
143+ this . _stopTimer = setTimeout ( ( ) => {
144+ this . logger . trace ( `streamWorkspaceStatus forcing cancel after 7 minutes` ) ;
145+ call . cancel ( ) ;
146+ } , 7 * 60 * 1000 /* 7 min */ ) ;
138147 }
139148
140149 public override dispose ( ) {
141150 super . dispose ( ) ;
151+ clearTimeout ( this . _stopTimer ) ;
142152 this . metricsReporter . stopReporting ( ) ;
143153 }
144154}
0 commit comments