Skip to content

Commit

Permalink
Remove old workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanp413 committed Oct 13, 2023
1 parent 05e1655 commit 7c452c8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 58 deletions.
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function activate(context: vscode.ExtensionContext) {
const hostService = new HostService(context, notificationService, logger);
context.subscriptions.push(hostService);

const sessionService = new SessionService(hostService, logger, telemetryService);
const sessionService = new SessionService(hostService, logger);
context.subscriptions.push(sessionService);

const remoteService = new RemoteService(context, hostService, sessionService, notificationService, telemetryService, logger);
Expand Down Expand Up @@ -119,7 +119,7 @@ export async function activate(context: vscode.ExtensionContext) {
commandManager.register(new InstallLocalExtensionsOnRemoteCommand(remoteService));
commandManager.register(new ExportLogsCommand(context, context.logUri, notificationService, telemetryService, logger, hostService));
// Backwards compatibility with older gitpod-remote extensions
commandManager.register({ id: 'gitpod.api.autoTunnel', execute: () => {} });
commandManager.register({ id: 'gitpod.api.autoTunnel', execute: () => { } });

if (!context.globalState.get<boolean>(FIRST_INSTALL_KEY, false)) {
context.globalState.update(FIRST_INSTALL_KEY, true);
Expand Down
74 changes: 21 additions & 53 deletions src/publicApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { timeout } from './common/async';
import { MetricsReporter, getConnectMetricsInterceptor } from './metrics';
import { ILogService } from './services/logService';
import { WrapError } from './common/utils';
import { ITelemetryService } from './common/telemetry';

function isTelemetryEnabled(): boolean {
const TELEMETRY_CONFIG_ID = 'telemetry';
Expand Down Expand Up @@ -60,7 +59,6 @@ export class GitpodPublicApi extends Disposable implements IGitpodAPI {
private readonly accessToken: string,
private readonly gitpodHost: string,
private readonly logger: ILogService,
private readonly telemetryService: ITelemetryService
) {
super();

Expand Down Expand Up @@ -97,70 +95,70 @@ export class GitpodPublicApi extends Disposable implements IGitpodAPI {
}

async listWorkspaces(): Promise<Workspace[]> {
return this._wrapError(this._workaroundGoAwayBug(async () => {
return this._wrapError(async () => {
const response = await this.workspaceService.listWorkspaces({});
return response.result;
}));
});
}

async getWorkspace(workspaceId: string, signal?: AbortSignal): Promise<Workspace> {
return this._wrapError(this._workaroundGoAwayBug(async () => {
return this._wrapError(async () => {
const response = await this.workspaceService.getWorkspace({ workspaceId });
return response.result!;
}), { signal });
}, { signal });
}

async startWorkspace(workspaceId: string): Promise<Workspace> {
return this._wrapError(this._workaroundGoAwayBug(async () => {
return this._wrapError(async () => {
const response = await this.workspaceService.startWorkspace({ workspaceId });
return response.result!;
}));
});
}

async stopWorkspace(workspaceId: string): Promise<Workspace> {
return this._wrapError(this._workaroundGoAwayBug(async () => {
return this._wrapError(async () => {
const response = await this.workspaceService.stopWorkspace({ workspaceId });
return response.result!;
}));
});
}

async deleteWorkspace(workspaceId: string): Promise<void> {
return this._wrapError(this._workaroundGoAwayBug(async () => {
return this._wrapError(async () => {
await this.workspaceService.deleteWorkspace({ workspaceId });
}));
});
}

async getOwnerToken(workspaceId: string, signal?: AbortSignal): Promise<string> {
return this._wrapError(this._workaroundGoAwayBug(async () => {
return this._wrapError(async () => {
const response = await this.workspaceService.getOwnerToken({ workspaceId });
return response.token;
}), { signal });
}, { signal });
}

async getSSHKeys(): Promise<SSHKey[]> {
return this._wrapError(this._workaroundGoAwayBug(async () => {
return this._wrapError(async () => {
const response = await this.userService.listSSHKeys({});
return response.keys;
}));
});
}

async sendHeartbeat(workspaceId: string): Promise<void> {
return this._wrapError(this._workaroundGoAwayBug(async () => {
return this._wrapError(async () => {
await this.ideClientService.sendHeartbeat({ workspaceId });
}));
});
}

async sendDidClose(workspaceId: string): Promise<void> {
return this._wrapError(this._workaroundGoAwayBug(async () => {
return this._wrapError(async () => {
await this.ideClientService.sendDidClose({ workspaceId });
}));
});
}

async getAuthenticatedUser(): Promise<User | undefined> {
return this._wrapError(this._workaroundGoAwayBug(async () => {
return this._wrapError(async () => {
const response = await this.userService.getAuthenticatedUser({});
return response.user;
}));
});
}

workspaceStatusStreaming(workspaceId: string) {
Expand All @@ -176,7 +174,7 @@ export class GitpodPublicApi extends Disposable implements IGitpodAPI {
if (isDisposed) { return; }

try {
const resp = await this._workaroundGoAwayBug(() => this.workspaceService.getWorkspace({ workspaceId }))();
const resp = await this.workspaceService.getWorkspace({ workspaceId });
if (isDisposed) { return; }
emitter.fire(resp.result!.status!);
} catch (err) {
Expand Down Expand Up @@ -225,15 +223,6 @@ export class GitpodPublicApi extends Disposable implements IGitpodAPI {
return;
}
this.logger.error(`Error in streamWorkspaceStatus for ${workspaceId}`, e);

// Workaround https://github.com/bufbuild/connect-es/issues/680
// Remove this once it's fixed upstream
const message: string = e.stack || e.message || `${e}`;
if (message.includes('New streams cannot be created after receiving a GOAWAY')) {
this.telemetryService.sendTelemetryException(e);
this.logger.error('Got GOAWAY bug, recreating connect client');
this.createClients();
}
}
}

Expand All @@ -258,27 +247,6 @@ export class GitpodPublicApi extends Disposable implements IGitpodAPI {
return callback().catch(onError);
}

private _workaroundGoAwayBug<T>(callback: () => Promise<T>): () => Promise<T> {
return async () => {
try {
return await callback();
} catch (e) {
// Workaround https://github.com/bufbuild/connect-es/issues/680
// Remove this once it's fixed upstream
const message: string = e.stack || e.message || `${e}`;
if (message.includes('New streams cannot be created after receiving a GOAWAY')) {
this.telemetryService.sendTelemetryException(e);
this.logger.error('Got GOAWAY bug, recreating connect client');
this.createClients();

return await callback();
} else {
throw e;
}
}
};
}

public override dispose() {
super.dispose();
for (const { dispose } of this.workspaceStatusStreamMap.values()) {
Expand Down
4 changes: 1 addition & 3 deletions src/services/sessionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { IHostService } from './hostService';
import { GitpodPublicApi, IGitpodAPI } from '../publicApi';
import { eventToPromise } from '../common/event';
import { ILogService } from './logService';
import { ITelemetryService } from '../common/telemetry';
import { arrayEquals } from '../common/utils';

export class NoSignedInError extends Error {
Expand Down Expand Up @@ -72,7 +71,6 @@ export class SessionService extends Disposable implements ISessionService {
constructor(
private readonly hostService: IHostService,
private readonly logger: ILogService,
private readonly telemetryService: ITelemetryService
) {
super();

Expand Down Expand Up @@ -187,7 +185,7 @@ export class SessionService extends Disposable implements ISessionService {
throw new NoSignedInError();
}
if (!this._publicApi) {
this._publicApi = new GitpodPublicApi(this.getGitpodToken(), this.hostService.gitpodHost, this.logger, this.telemetryService);
this._publicApi = new GitpodPublicApi(this.getGitpodToken(), this.hostService.gitpodHost, this.logger);
}
return this._publicApi;
}
Expand Down

0 comments on commit 7c452c8

Please sign in to comment.