Skip to content

Commit c180d50

Browse files
committed
Update pid
1 parent 639911b commit c180d50

File tree

1 file changed

+37
-23
lines changed

1 file changed

+37
-23
lines changed

src/remote.ts

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -274,55 +274,69 @@ export class Remote {
274274
// We can ignore this, it's probably blank!
275275
}
276276
})
277+
let remotePID = 0
277278
// 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+
279292
let remotePort = 0
280293
if (running.filter((instance) => instance.commit === this.vscodeCommit)) {
281294
await this.ipc.execute(shell, `cat ${portFilePath}`, (data) => {
282295
if (data.trim()) {
283296
remotePort = Number.parseInt(data.trim())
284297
}
285298
})
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+
}
288302
}
289303

290304
if (!remotePort) {
291305
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+
297312
this.ipc
298313
?.execute(shell, script, (data) => {
299314
const lines = data.split("\n")
300315
lines.forEach((line) => {
301316
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())
308320
}
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))
312331
}
313-
resolve(Number.parseInt(port))
314332
})
315333
})
316334
.then((exitCode) => {
317335
reject("Exited with: " + exitCode)
318336
})
319337
})
320338

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)
326340
}
327341

328342
const forwarded = await this.ipc.portForward(remotePort)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy