Skip to content

Commit 8134f1f

Browse files
Recreate REST client after starting a workspace (part 2) (#436)
Co-authored-by: Benjamin Peinhardt <[email protected]>
1 parent 71f5ba5 commit 8134f1f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Fixed
6+
7+
- Recreate REST client in spots where confirmStart may have waited indefinitely.
8+
59
## [v1.4.0](https://github.com/coder/vscode-coder/releases/tag/v1.3.9) (2025-02-04)
610

711
- Recreate REST client after starting a workspace to ensure fresh TLS certificates.

src/remote.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ export class Remote {
5151
* Try to get the workspace running. Return undefined if the user canceled.
5252
*/
5353
private async maybeWaitForRunning(
54-
restClient: Api,
5554
workspace: Workspace,
5655
label: string,
5756
binPath: string,
57+
baseUrlRaw: string,
58+
token: string,
5859
): Promise<Workspace | undefined> {
5960
const workspaceName = `${workspace.owner_name}/${workspace.name}`
6061

@@ -94,6 +95,7 @@ export class Remote {
9495
title: "Waiting for workspace build...",
9596
},
9697
async () => {
98+
let restClient = await makeCoderSdk(baseUrlRaw, token, this.storage)
9799
const globalConfigDir = path.dirname(this.storage.getSessionTokenPath(label))
98100
while (workspace.latest_build.status !== "running") {
99101
++attempts
@@ -109,6 +111,9 @@ export class Remote {
109111
if (!(await this.confirmStart(workspaceName))) {
110112
return undefined
111113
}
114+
// Recreate REST client since confirmStart may have waited an
115+
// indeterminate amount of time for confirmation.
116+
restClient = await makeCoderSdk(baseUrlRaw, token, this.storage)
112117
writeEmitter = initWriteEmitterAndTerminal()
113118
this.storage.writeToCoderOutputChannel(`Starting ${workspaceName}...`)
114119
workspace = await startWorkspaceIfStoppedOrFailed(
@@ -126,6 +131,9 @@ export class Remote {
126131
if (!(await this.confirmStart(workspaceName))) {
127132
return undefined
128133
}
134+
// Recreate REST client since confirmStart may have waited an
135+
// indeterminate amount of time for confirmation.
136+
restClient = await makeCoderSdk(baseUrlRaw, token, this.storage)
129137
writeEmitter = initWriteEmitterAndTerminal()
130138
this.storage.writeToCoderOutputChannel(`Starting ${workspaceName}...`)
131139
workspace = await startWorkspaceIfStoppedOrFailed(
@@ -316,7 +324,7 @@ export class Remote {
316324

317325
// If the workspace is not in a running state, try to get it running.
318326
if (workspace.latest_build.status !== "running") {
319-
if (!(await this.maybeWaitForRunning(workspaceRestClient, workspace, parts.label, binaryPath))) {
327+
if (!(await this.maybeWaitForRunning(workspace, parts.label, binaryPath, baseUrlRaw, token))) {
320328
// User declined to start the workspace.
321329
await this.closeRemote()
322330
} else {

0 commit comments

Comments
 (0)