Skip to content

Commit 60d3363

Browse files
committed
Add retry on unavailable
1 parent 03638cf commit 60d3363

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/local-ssh/ipc/extensionServiceServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
121121
} catch (e) {
122122
let code = Status.INTERNAL;
123123
if (e instanceof WrapError && typeof e.grpcCode === 'number') {
124-
code = e.grpcCode
124+
code = e.grpcCode;
125125
}
126126
const wrapErr = new WrapError('failed to get workspace auth info', e);
127127
this.logService.error(wrapErr);

src/publicApi.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,23 @@ export class GitpodPublicApi extends Disposable implements IGitpodAPI {
208208
}
209209

210210
private async _wrapError<T>(callback: () => Promise<T>): Promise<T> {
211-
try {
212-
return await callback();
213-
} catch (e) {
211+
const maxRetries = 5;
212+
let retries = 0;
213+
214+
const onError: (e: any) => Promise<T> = async (e) => {
214215
const err = ConnectError.from(e);
216+
if (retries++ < maxRetries && (err.code === Code.Unavailable || err.code === Code.Aborted)) {
217+
await timeout(1000);
218+
return callback().catch(onError);
219+
}
220+
215221
// https://github.com/gitpod-io/gitpod/blob/d41a38ba83939856e5292e30912f52e749787db1/components/public-api-server/pkg/auth/middleware.go#L73
216222
// https://github.com/gitpod-io/gitpod/blob/d41a38ba83939856e5292e30912f52e749787db1/components/public-api-server/pkg/proxy/errors.go#L30
217223
// NOTE: WrapError will omit error's other properties
218224
throw new WrapError('Failed to call public API', err, 'PublicAPI:' + Code[err.code], err.code);
219-
}
225+
};
226+
227+
return callback().catch(onError);
220228
}
221229

222230
private _workaroundGoAwayBug<T>(callback: () => Promise<T>): () => Promise<T> {

src/workspaceState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class WorkspaceState extends Disposable {
2020
readonly onWorkspaceStateChanged = this._onWorkspaceStateChanged.event;
2121

2222
readonly onWorkspaceRunning = onceEvent(filterEvent(this.onWorkspaceStateChanged, () => this.isWorkspaceRunning));
23-
readonly onWorkspaceWillStop = onceEvent(filterEvent(this.onWorkspaceStateChanged, () => this.isWorkspaceStopping));
23+
readonly onWorkspaceWillStop = onceEvent(filterEvent(this.onWorkspaceStateChanged, () => this.isWorkspaceStopping || this.isWorkspaceStopped /* it's not guranteed to get stoppping state so check stopped too */));
2424
readonly onWorkspaceStopped = onceEvent(filterEvent(this.onWorkspaceStateChanged, () => this.isWorkspaceStopped));
2525

2626
public get isWorkspaceStopping() {

0 commit comments

Comments
 (0)