Skip to content

Commit 0e0485d

Browse files
akosyakovjeanp413
authored andcommitted
[desktop] don't restart local app if failed to run
1 parent 12d929a commit 0e0485d

File tree

3 files changed

+26
-30
lines changed

3 files changed

+26
-30
lines changed

extensions/gitpod-remote/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "%displayName%",
44
"description": "%description%",
55
"publisher": "gitpod",
6-
"version": "0.0.22",
6+
"version": "0.0.24",
77
"license": "MIT",
88
"preview": true,
99
"icon": "resources/gitpod.png",

extensions/gitpod/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "%displayName%",
44
"description": "%description%",
55
"publisher": "gitpod",
6-
"version": "0.0.22",
6+
"version": "0.0.24",
77
"license": "MIT",
88
"preview": true,
99
"icon": "resources/gitpod.png",

extensions/gitpod/src/extension.ts

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ export async function activate(context: vscode.ExtensionContext) {
113113
const releaseStaleLocksTimer = setInterval(() => releaseStaleLocks(), fastLockTimeout);
114114
context.subscriptions.push(new vscode.Disposable(() => clearInterval(releaseStaleLocksTimer)));
115115

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+
116125
function downloadLocalApp(gitpodHost: string): Promise<Response> {
117126
let downloadUri = vscode.Uri.parse(gitpodHost);
118127
if (process.platform === 'win32') {
@@ -223,10 +232,9 @@ export async function activate(context: vscode.ExtensionContext) {
223232
// TODO(ak) when Node.js > 14.17
224233
// localAppProcess.on('spwan', () => resolve(localAppProcess.pid)));
225234
spawnTimer = setInterval(() => {
226-
try {
227-
process.kill(localAppProcess.pid, 0);
235+
if (checkRunning(localAppProcess.pid) === true) {
228236
resolve(localAppProcess.pid);
229-
} catch { }
237+
}
230238
}, 150);
231239
}
232240
}).finally(() => {
@@ -251,6 +259,10 @@ export async function activate(context: vscode.ExtensionContext) {
251259
let config = context.globalState.get<LocalAppConfig>(configKey);
252260
let installation = context.globalState.get<LocalAppInstallation>(installationKey);
253261

262+
if (config && checkRunning(config?.pid) !== true) {
263+
config = undefined;
264+
}
265+
254266
const gitpodConfig = vscode.workspace.getConfiguration('gitpod');
255267
const configuredInstallationPath = gitpodConfig.get<string>('installationPath');
256268
if (configuredInstallationPath) {
@@ -330,49 +342,33 @@ export async function activate(context: vscode.ExtensionContext) {
330342
const gitpodAuthority = vscode.Uri.parse(gitpodHost).authority;
331343
const configKey = 'config/' + gitpodAuthority;
332344
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) {
339350
const client = new LocalAppClient('http://localhost:' + config.apiPort, { transport: NodeHttpTransport() });
340351
try {
341352
const result = await op(client, config);
342353
throwIfCancelled(token);
343354
return result;
344355
} catch (e) {
345356
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);
353358
if (running === true && (e.code === grpc.Code.Unavailable || e.code === grpc.Code.Unknown)) {
354359
log(`the local app (pid: ${config.pid}) is running, but the api endpoint is not ready: ${e}`);
355360
log(`retying again after 1s delay...`);
356361
await new Promise(resolve => setTimeout(resolve, 1000));
357362
throwIfCancelled(token);
358363
continue;
359364
}
360-
if (running === true) {
361-
throw e;
365+
if (running !== true) {
366+
log(`the local app (pid: ${config.pid}) is not running: ${running}`);
362367
}
363368
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;
373370
}
374371
}
375-
throw new Error('failed to access the local app');
376372
}
377373

378374
const authCompletePath = '/auth-complete';

0 commit comments

Comments
 (0)