From c4f4b2a93feb47c4bd516115ccb6a06c4ac87f7b Mon Sep 17 00:00:00 2001 From: Aaron Lehmann Date: Wed, 19 Feb 2025 10:52:53 -0800 Subject: [PATCH 1/2] Recreate REST client after starting a workspace (part 2) This is a followup to #431. It addresses the need to also recreate the REST client used inside `maybeWaitForRunning`, since it makes API calls before returning to `setup`. --- src/remote.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/remote.ts b/src/remote.ts index 9b7f6f8a..ace2a378 100644 --- a/src/remote.ts +++ b/src/remote.ts @@ -51,10 +51,11 @@ export class Remote { * Try to get the workspace running. Return undefined if the user canceled. */ private async maybeWaitForRunning( - restClient: Api, workspace: Workspace, label: string, binPath: string, + baseUrlRaw: string, + token: string, ): Promise { const workspaceName = `${workspace.owner_name}/${workspace.name}` @@ -94,6 +95,7 @@ export class Remote { title: "Waiting for workspace build...", }, async () => { + let restClient = await makeCoderSdk(baseUrlRaw, token, this.storage) const globalConfigDir = path.dirname(this.storage.getSessionTokenPath(label)) while (workspace.latest_build.status !== "running") { ++attempts @@ -109,6 +111,9 @@ export class Remote { if (!(await this.confirmStart(workspaceName))) { return undefined } + // Recreate REST client since confirmStart may have waited an + // indeterminate amount of time for confirmation. + restClient = await makeCoderSdk(baseUrlRaw, token, this.storage) writeEmitter = initWriteEmitterAndTerminal() this.storage.writeToCoderOutputChannel(`Starting ${workspaceName}...`) workspace = await startWorkspaceIfStoppedOrFailed( @@ -126,6 +131,9 @@ export class Remote { if (!(await this.confirmStart(workspaceName))) { return undefined } + // Recreate REST client since confirmStart may have waited an + // indeterminate amount of time for confirmation. + restClient = await makeCoderSdk(baseUrlRaw, token, this.storage) writeEmitter = initWriteEmitterAndTerminal() this.storage.writeToCoderOutputChannel(`Starting ${workspaceName}...`) workspace = await startWorkspaceIfStoppedOrFailed( @@ -316,7 +324,7 @@ export class Remote { // If the workspace is not in a running state, try to get it running. if (workspace.latest_build.status !== "running") { - if (!(await this.maybeWaitForRunning(workspaceRestClient, workspace, parts.label, binaryPath))) { + if (!(await this.maybeWaitForRunning(workspace, parts.label, binaryPath, baseUrlRaw, token))) { // User declined to start the workspace. await this.closeRemote() } else { From 97d863cd6da8e3504eaad3f0e2d8cfbe2e1793f8 Mon Sep 17 00:00:00 2001 From: Benjamin Peinhardt Date: Wed, 19 Feb 2025 19:53:29 +0000 Subject: [PATCH 2/2] changelog update --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b048df8..851f7c7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Fixed + +- Recreate REST client in spots where confirmStart may have waited indefinitely. + ## [v1.4.0](https://github.com/coder/vscode-coder/releases/tag/v1.3.9) (2025-02-04) - Recreate REST client after starting a workspace to ensure fresh TLS certificates.