@@ -113,6 +113,15 @@ export async function activate(context: vscode.ExtensionContext) {
113
113
const releaseStaleLocksTimer = setInterval ( ( ) => releaseStaleLocks ( ) , fastLockTimeout ) ;
114
114
context . subscriptions . push ( new vscode . Disposable ( ( ) => clearInterval ( releaseStaleLocksTimer ) ) ) ;
115
115
116
+ function checkRunning ( pid : number ) : true | Error {
117
+ try {
118
+ process . kill ( pid , 0 ) ;
119
+ return true ;
120
+ } catch ( e ) {
121
+ return e ;
122
+ }
123
+ }
124
+
116
125
function downloadLocalApp ( gitpodHost : string ) : Promise < Response > {
117
126
let downloadUri = vscode . Uri . parse ( gitpodHost ) ;
118
127
if ( process . platform === 'win32' ) {
@@ -223,10 +232,9 @@ export async function activate(context: vscode.ExtensionContext) {
223
232
// TODO(ak) when Node.js > 14.17
224
233
// localAppProcess.on('spwan', () => resolve(localAppProcess.pid)));
225
234
spawnTimer = setInterval ( ( ) => {
226
- try {
227
- process . kill ( localAppProcess . pid , 0 ) ;
235
+ if ( checkRunning ( localAppProcess . pid ) === true ) {
228
236
resolve ( localAppProcess . pid ) ;
229
- } catch { }
237
+ }
230
238
} , 150 ) ;
231
239
}
232
240
} ) . finally ( ( ) => {
@@ -251,6 +259,10 @@ export async function activate(context: vscode.ExtensionContext) {
251
259
let config = context . globalState . get < LocalAppConfig > ( configKey ) ;
252
260
let installation = context . globalState . get < LocalAppInstallation > ( installationKey ) ;
253
261
262
+ if ( config && checkRunning ( config ?. pid ) !== true ) {
263
+ config = undefined ;
264
+ }
265
+
254
266
const gitpodConfig = vscode . workspace . getConfiguration ( 'gitpod' ) ;
255
267
const configuredInstallationPath = gitpodConfig . get < string > ( 'installationPath' ) ;
256
268
if ( configuredInstallationPath ) {
@@ -330,49 +342,33 @@ export async function activate(context: vscode.ExtensionContext) {
330
342
const gitpodAuthority = vscode . Uri . parse ( gitpodHost ) . authority ;
331
343
const configKey = 'config/' + gitpodAuthority ;
332
344
const installationKey = 'installation/' + gitpodAuthority ;
333
- let restartAttempts = 0 ;
334
- while ( restartAttempts < 5 ) {
335
- const config = await withLock ( gitpodAuthority , token =>
336
- ensureLocalApp ( gitpodHost , configKey , installationKey , token )
337
- , slowLockTimeout , token ) ;
338
- throwIfCancelled ( token ) ;
345
+ const config = await withLock ( gitpodAuthority , token =>
346
+ ensureLocalApp ( gitpodHost , configKey , installationKey , token )
347
+ , slowLockTimeout , token ) ;
348
+ throwIfCancelled ( token ) ;
349
+ while ( true ) {
339
350
const client = new LocalAppClient ( 'http://localhost:' + config . apiPort , { transport : NodeHttpTransport ( ) } ) ;
340
351
try {
341
352
const result = await op ( client , config ) ;
342
353
throwIfCancelled ( token ) ;
343
354
return result ;
344
355
} catch ( e ) {
345
356
throwIfCancelled ( token ) ;
346
- let running : true | Error ;
347
- try {
348
- process . kill ( config . pid , 0 ) ;
349
- running = true ;
350
- } catch ( e2 ) {
351
- running = e2 ;
352
- }
357
+ const running = checkRunning ( config . pid ) ;
353
358
if ( running === true && ( e . code === grpc . Code . Unavailable || e . code === grpc . Code . Unknown ) ) {
354
359
log ( `the local app (pid: ${ config . pid } ) is running, but the api endpoint is not ready: ${ e } ` ) ;
355
360
log ( `retying again after 1s delay...` ) ;
356
361
await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
357
362
throwIfCancelled ( token ) ;
358
363
continue ;
359
364
}
360
- if ( running = == true ) {
361
- throw e ;
365
+ if ( running ! == true ) {
366
+ log ( `the local app (pid: ${ config . pid } ) is not running: ${ running } ` ) ;
362
367
}
363
368
log ( `failed to access the local app: ${ e } ` ) ;
364
- log ( `the local app (pid: ${ config . pid } ) is not running: ${ running } ` ) ;
365
- log ( `restarting the local app...` ) ;
366
- await withLock ( gitpodAuthority , async ( ) => {
367
- if ( JSON . stringify ( context . globalState . get < LocalAppConfig > ( configKey ) ) === JSON . stringify ( config ) ) {
368
- await context . globalState . update ( configKey , undefined ) ;
369
- }
370
- } , fastLockTimeout , token ) ;
371
- throwIfCancelled ( token ) ;
372
- restartAttempts ++ ;
369
+ throw e ;
373
370
}
374
371
}
375
- throw new Error ( 'failed to access the local app' ) ;
376
372
}
377
373
378
374
const authCompletePath = '/auth-complete' ;
0 commit comments