Skip to content

Commit a9f3b1f

Browse files
mustard-mhjeanp413
authored andcommitted
Add retry to avoid network problem
- Add phase for NoRunningInstanceError - Filter out instance not running error
1 parent d7cb844 commit a9f3b1f

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/remoteConnector.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { LocalAppClient } from '@gitpod/local-app-api-grpcweb/lib/localapp_pb_se
99
import { NodeHttpTransport } from '@improbable-eng/grpc-web-node-http-transport';
1010
import { grpc } from '@improbable-eng/grpc-web';
1111
import { Workspace, WorkspaceInstanceStatus_Phase } from '@gitpod/public-api/lib/gitpod/experimental/v1/workspaces_pb';
12-
import { UserSSHPublicKeyValue, WorkspaceInfo } from '@gitpod/gitpod-protocol';
12+
import { UserSSHPublicKeyValue, WorkspaceInfo, WorkspaceInstancePhase } from '@gitpod/gitpod-protocol';
1313
import * as cp from 'child_process';
1414
import * as fs from 'fs';
1515
import * as http from 'http';
@@ -110,8 +110,8 @@ class LocalAppError extends Error {
110110
}
111111

112112
class NoRunningInstanceError extends Error {
113-
constructor(readonly workspaceId: string) {
114-
super(`Failed to connect to ${workspaceId} Gitpod workspace, workspace not running`);
113+
constructor(readonly workspaceId: string, phase?: WorkspaceInstancePhase) {
114+
super(`Failed to connect to ${workspaceId} Gitpod workspace, workspace not running: ${phase}`);
115115
}
116116
}
117117

@@ -1024,9 +1024,12 @@ export default class RemoteConnector extends Disposable {
10241024
throw new Error('No Gitpod session available');
10251025
}
10261026

1027-
const workspaceInfo = await withServerApi(session.accessToken, connectionInfo.gitpodHost, service => service.server.getWorkspace(connectionInfo.workspaceId), this.logger);
1027+
const workspaceInfo = await retry(async () => {
1028+
return await withServerApi(session!.accessToken, connectionInfo.gitpodHost, service => service.server.getWorkspace(connectionInfo.workspaceId), this.logger);
1029+
}, 500, 3);
1030+
10281031
if (workspaceInfo.latestInstance?.status?.phase !== 'running') {
1029-
throw new NoRunningInstanceError(connectionInfo.workspaceId);
1032+
throw new NoRunningInstanceError(connectionInfo.workspaceId, workspaceInfo.latestInstance?.status?.phase);
10301033
}
10311034

10321035
if (workspaceInfo.latestInstance.id !== connectionInfo.instanceId) {
@@ -1069,8 +1072,12 @@ export default class RemoteConnector extends Disposable {
10691072

10701073
vscode.commands.executeCommand('setContext', 'gitpod.inWorkspace', true);
10711074
} catch (e) {
1072-
e.message = `Failed to resolve whole gitpod remote connection process: ${e.message}`;
1073-
this.logger.error(e);
1075+
if (e instanceof NoRunningInstanceError) {
1076+
this.logger.error('No Running instance:', e);
1077+
return;
1078+
}
1079+
e.message = `Failed to resolve whole gitpod remote connection process: ${e.message}`;
1080+
this.logger.error(e);
10741081
this.telemetry.sendTelemetryException(e, { workspaceId: connectionInfo.workspaceId, instanceId: connectionInfo.instanceId, userId: session?.account.id || '' });
10751082
}
10761083
}

0 commit comments

Comments
 (0)