Skip to content

Commit c709288

Browse files
committed
Max WS retries
1 parent 3cf80cd commit c709288

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

extensions/gitpod/src/auth.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,24 @@ async function createApiWebSocket(accessToken: string): Promise<{ gitpodService:
248248
});
249249
}
250250
}
251+
const webSocketMaxRetries = 3;
251252
const webSocket = new ReconnectingWebSocket(baseURL.replace('https', 'wss'), undefined, {
252253
minReconnectionDelay: 1000,
253254
connectionTimeout: 10000,
254-
maxRetries: 10,
255+
maxRetries: webSocketMaxRetries,
255256
debug: false,
256257
startClosed: false,
257258
WebSocket: GitpodServerWebSocket
258259
});
260+
261+
let retry = 1;
259262
webSocket.onerror = (err) => {
260-
vscode.window.showErrorMessage(`WebSocket error: ${err.message}`);
263+
vscode.window.showErrorMessage(`WebSocket error: ${err.message} (#${retry}/${webSocketMaxRetries})`);
264+
if (retry++ === webSocketMaxRetries) {
265+
throw new Error('Maximum websocket connection retries exceeded');
266+
}
261267
};
268+
262269
doListen({
263270
webSocket,
264271
logger: new ConsoleLogger(),
@@ -373,7 +380,7 @@ export function registerAuth(context: vscode.ExtensionContext, logger: (value: s
373380
context.subscriptions.push(addCmd);
374381

375382
async function createSession(scopes: readonly string[]): Promise<vscode.AuthenticationSession> {
376-
const callbackUri = await vscode.env.asExternalUri(vscode.Uri.parse(`${vscode.env.uriScheme}://gitpod.gitpod-desktop/complete-gitpod-auth`));
383+
const callbackUri = vscode.Uri.parse(`${vscode.env.uriScheme}://gitpod.gitpod-desktop/complete-gitpod-auth`);
377384

378385
if (![...gitpodScopes].every((scope) => scopes.includes(scope))) {
379386
vscode.window.showErrorMessage('The provided scopes are not enough to turn on Settings Sync');

0 commit comments

Comments
 (0)