Skip to content

Commit ac86aa9

Browse files
committed
Recreate REST client after starting a workspace
maybeWaitForRunning can take indefinitely long because it prompts for confirmation, and in that time, client certificates can expire. Start setup fresh after this call to make sure the REST client uses the latest certificates.
1 parent 4dd0d70 commit ac86aa9

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/remote.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ export class Remote {
5656
label: string,
5757
binPath: string,
5858
): Promise<Workspace | undefined> {
59-
// Maybe already running?
60-
if (workspace.latest_build.status === "running") {
61-
return workspace
62-
}
63-
6459
const workspaceName = `${workspace.owner_name}/${workspace.name}`
6560

6661
// A terminal will be used to stream the build, if one is necessary.
@@ -320,13 +315,19 @@ export class Remote {
320315
disposables.push(this.registerLabelFormatter(remoteAuthority, workspace.owner_name, workspace.name))
321316

322317
// If the workspace is not in a running state, try to get it running.
323-
const updatedWorkspace = await this.maybeWaitForRunning(workspaceRestClient, workspace, parts.label, binaryPath)
324-
if (!updatedWorkspace) {
325-
// User declined to start the workspace.
326-
await this.closeRemote()
318+
if (workspace.latest_build.status !== "running") {
319+
if (!(await this.maybeWaitForRunning(workspaceRestClient, workspace, parts.label, binaryPath))) {
320+
// User declined to start the workspace.
321+
await this.closeRemote()
322+
} else {
323+
// Start over with a fresh REST client because we may have waited an
324+
// indeterminate amount amount of time for confirmation to start the
325+
// workspace.
326+
await this.setup(remoteAuthority)
327+
}
327328
return
328329
}
329-
this.commands.workspace = workspace = updatedWorkspace
330+
this.commands.workspace = workspace
330331

331332
// Pick an agent.
332333
this.storage.writeToCoderOutputChannel(`Finding agent for ${workspaceName}...`)

0 commit comments

Comments
 (0)