@@ -51,10 +51,11 @@ export class Remote {
51
51
* Try to get the workspace running. Return undefined if the user canceled.
52
52
*/
53
53
private async maybeWaitForRunning (
54
- restClient : Api ,
55
54
workspace : Workspace ,
56
55
label : string ,
57
56
binPath : string ,
57
+ baseUrlRaw : string ,
58
+ token : string ,
58
59
) : Promise < Workspace | undefined > {
59
60
const workspaceName = `${ workspace . owner_name } /${ workspace . name } `
60
61
@@ -94,6 +95,7 @@ export class Remote {
94
95
title : "Waiting for workspace build..." ,
95
96
} ,
96
97
async ( ) => {
98
+ let restClient = await makeCoderSdk ( baseUrlRaw , token , this . storage )
97
99
const globalConfigDir = path . dirname ( this . storage . getSessionTokenPath ( label ) )
98
100
while ( workspace . latest_build . status !== "running" ) {
99
101
++ attempts
@@ -109,6 +111,9 @@ export class Remote {
109
111
if ( ! ( await this . confirmStart ( workspaceName ) ) ) {
110
112
return undefined
111
113
}
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 )
112
117
writeEmitter = initWriteEmitterAndTerminal ( )
113
118
this . storage . writeToCoderOutputChannel ( `Starting ${ workspaceName } ...` )
114
119
workspace = await startWorkspaceIfStoppedOrFailed (
@@ -126,6 +131,9 @@ export class Remote {
126
131
if ( ! ( await this . confirmStart ( workspaceName ) ) ) {
127
132
return undefined
128
133
}
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 )
129
137
writeEmitter = initWriteEmitterAndTerminal ( )
130
138
this . storage . writeToCoderOutputChannel ( `Starting ${ workspaceName } ...` )
131
139
workspace = await startWorkspaceIfStoppedOrFailed (
@@ -316,7 +324,7 @@ export class Remote {
316
324
317
325
// If the workspace is not in a running state, try to get it running.
318
326
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 ) ) ) {
320
328
// User declined to start the workspace.
321
329
await this . closeRemote ( )
322
330
} else {
0 commit comments