Skip to content

Commit 6e040ed

Browse files
committed
Use grpc signal to stop retry
1 parent 990ae06 commit 6e040ed

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/local-ssh/ipc/extensionServiceServer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
9696
const gitpodHost = this.hostService.gitpodHost;
9797
const usePublicApi = await this.experiments.getUsePublicAPI(gitpodHost);
9898
const [workspace, ownerToken] = await withServerApi(accessToken, gitpodHost, svc => Promise.all([
99-
usePublicApi ? this.sessionService.getAPI().getWorkspace(actualWorkspaceId) : svc.server.getWorkspace(actualWorkspaceId),
100-
usePublicApi ? this.sessionService.getAPI().getOwnerToken(actualWorkspaceId) : svc.server.getOwnerToken(actualWorkspaceId),
99+
usePublicApi ? this.sessionService.getAPI().getWorkspace(actualWorkspaceId, _context.signal) : svc.server.getWorkspace(actualWorkspaceId),
100+
usePublicApi ? this.sessionService.getAPI().getOwnerToken(actualWorkspaceId, _context.signal) : svc.server.getOwnerToken(actualWorkspaceId),
101101
]), this.logService);
102102

103103
const phase = usePublicApi ? phaseMap[(workspace as Workspace).status?.instance?.status?.phase ?? WorkspaceInstanceStatus_Phase.UNSPECIFIED] : (workspace as WorkspaceInfo).latestInstance?.status.phase;

src/publicApi.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ function isTelemetryEnabled(): boolean {
3333
}
3434

3535
export interface IGitpodAPI {
36-
getWorkspace(workspaceId: string): Promise<Workspace>;
36+
getWorkspace(workspaceId: string, signal?: AbortSignal): Promise<Workspace>;
3737
startWorkspace(workspaceId: string): Promise<Workspace>;
38-
getOwnerToken(workspaceId: string): Promise<string>;
38+
getOwnerToken(workspaceId: string, signal?: AbortSignal): Promise<string>;
3939
getSSHKeys(): Promise<SSHKey[]>;
4040
sendHeartbeat(workspaceId: string): Promise<void>;
4141
sendDidClose(workspaceId: string): Promise<void>;
@@ -93,11 +93,11 @@ export class GitpodPublicApi extends Disposable implements IGitpodAPI {
9393
}
9494

9595

96-
async getWorkspace(workspaceId: string): Promise<Workspace> {
96+
async getWorkspace(workspaceId: string, signal?: AbortSignal): Promise<Workspace> {
9797
return this._wrapError(this._workaroundGoAwayBug(async () => {
9898
const response = await this.workspaceService.getWorkspace({ workspaceId });
9999
return response.result!;
100-
}));
100+
}), { signal });
101101
}
102102

103103
async startWorkspace(workspaceId: string): Promise<Workspace> {
@@ -107,11 +107,11 @@ export class GitpodPublicApi extends Disposable implements IGitpodAPI {
107107
}));
108108
}
109109

110-
async getOwnerToken(workspaceId: string): Promise<string> {
110+
async getOwnerToken(workspaceId: string, signal?: AbortSignal): Promise<string> {
111111
return this._wrapError(this._workaroundGoAwayBug(async () => {
112112
const response = await this.workspaceService.getOwnerToken({ workspaceId });
113113
return response.token;
114-
}));
114+
}), { signal });
115115
}
116116

117117
async getSSHKeys(): Promise<SSHKey[]> {
@@ -214,13 +214,14 @@ export class GitpodPublicApi extends Disposable implements IGitpodAPI {
214214
}
215215
}
216216

217-
private async _wrapError<T>(callback: () => Promise<T>): Promise<T> {
218-
const maxRetries = 5;
217+
private async _wrapError<T>(callback: () => Promise<T>, opts?: { maxRetries?: number; signal?: AbortSignal }): Promise<T> {
218+
const maxRetries = opts?.maxRetries ?? 5;
219219
let retries = 0;
220220

221221
const onError: (e: any) => Promise<T> = async (e) => {
222222
const err = ConnectError.from(e);
223-
if (retries++ < maxRetries && (err.code === Code.Unavailable || err.code === Code.Aborted)) {
223+
const shouldRetry = opts?.signal ? !opts.signal.aborted : retries++ < maxRetries;
224+
if (shouldRetry && (err.code === Code.Unavailable || err.code === Code.Aborted)) {
224225
await timeout(1000);
225226
return callback().catch(onError);
226227
}

0 commit comments

Comments
 (0)