@@ -274,55 +274,69 @@ export class Remote {
274
274
// We can ignore this, it's probably blank!
275
275
}
276
276
} )
277
+ let remotePID = 0
277
278
// Store the running port for the current commit in a file for reconnection!
278
- const portFilePath = `/tmp/.vscode-remote-${ this . vscodeCommit } -port`
279
+ const portFilePath = ( pid = remotePID ) => {
280
+ return `/tmp/.vscode-remote-${ pid } `
281
+ }
282
+ const filtered = running . filter ( ( instance ) => instance . commit === this . vscodeCommit )
283
+ if ( filtered . length ) {
284
+ remotePID = filtered [ 0 ] . process_id
285
+ await this . ipc . execute ( shell , `cat${ portFilePath ( remotePID ) } ` , ( data ) => {
286
+ if ( data . trim ( ) ) {
287
+ remotePort = Number . parseInt ( data . trim ( ) )
288
+ }
289
+ } )
290
+ }
291
+
279
292
let remotePort = 0
280
293
if ( running . filter ( ( instance ) => instance . commit === this . vscodeCommit ) ) {
281
294
await this . ipc . execute ( shell , `cat${ portFilePath } ` , ( data ) => {
282
295
if ( data . trim ( ) ) {
283
296
remotePort = Number . parseInt ( data . trim ( ) )
284
297
}
285
298
} )
286
-
287
- this . output . appendLine ( "Found existing server running on port: " + remotePort )
299
+ if ( remotePort ) {
300
+ this . output . appendLine ( "Found existing server running on port: " + remotePort )
301
+ }
288
302
}
289
303
290
304
if ( ! remotePort ) {
291
305
remotePort = await new Promise < number > ( ( resolve , reject ) => {
292
- const script =
293
- binPath +
294
- " serve-local --start-server --port 0 --without-connection-token --commit-id " +
295
- this . vscodeCommit +
296
- " --accept-server-license-terms"
306
+ const script = `
307
+ ${ binPath } serve-local --start-server --port 0 --without-connection-token --commit-id${ this . vscodeCommit } --accept-server-license-terms &
308
+ echo "PID: $!"
309
+ wait
310
+ `
311
+
297
312
this . ipc
298
313
?. execute ( shell , script , ( data ) => {
299
314
const lines = data . split ( "\n" )
300
315
lines . forEach ( ( line ) => {
301
316
this . output . appendLine ( line )
302
- if ( ! line . startsWith ( "Server bound to" ) ) {
303
- return
304
- }
305
- const parts = line . split ( " " ) . filter ( ( part ) => part . startsWith ( "127.0.0.1:" ) )
306
- if ( parts . length === 0 ) {
307
- return reject ( "No port found in output: " + line )
317
+ if ( line . startsWith ( "PID: " ) ) {
318
+ console . log ( "WE GOT PID" , line )
319
+ remotePID = Number . parseInt ( line . split ( "PID: " ) [ 1 ] . trim ( ) )
308
320
}
309
- const port = parts [ 0 ] . split ( ":" ) . pop ( )
310
- if ( ! port ) {
311
- return reject ( "No port found in parts: " + parts . join ( "," ) )
321
+ if ( line . startsWith ( "Server bound to" ) ) {
322
+ const parts = line . split ( " " ) . filter ( ( part ) => part . startsWith ( "127.0.0.1:" ) )
323
+ if ( parts . length === 0 ) {
324
+ return reject ( "No port found in output: " + line )
325
+ }
326
+ const port = parts [ 0 ] . split ( ":" ) . pop ( )
327
+ if ( ! port ) {
328
+ return reject ( "No port found in parts: " + parts . join ( "," ) )
329
+ }
330
+ resolve ( Number . parseInt ( port ) )
312
331
}
313
- resolve ( Number . parseInt ( port ) )
314
332
} )
315
333
} )
316
334
. then ( ( exitCode ) => {
317
335
reject ( "Exited with: " + exitCode )
318
336
} )
319
337
} )
320
338
321
- await this . ipc . execute (
322
- shell ,
323
- `echo${ remotePort } > /tmp/.vscode-remote-${ this . vscodeCommit } -port` ,
324
- ( ) => undefined ,
325
- )
339
+ await this . ipc . execute ( shell , `echo${ remotePort } >${ portFilePath ( remotePID ) } ` , ( ) => undefined )
326
340
}
327
341
328
342
const forwarded = await this . ipc . portForward ( remotePort )