Skip to content

Commit af71203

Browse files
committed
Fix relaunching during an update
1 parent fc3acfa commit af71203

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"patch:apply": "cd ../../../ && git apply ./src/vs/server/scripts/vscode.patch"
1212
},
1313
"devDependencies": {
14-
"@coder/nbin": "^1.2.2",
14+
"@coder/nbin": "^1.2.3",
1515
"@types/fs-extra": "^8.0.1",
1616
"@types/node": "^10.12.12",
1717
"@types/pem": "^1.9.5",

src/node/cli.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,14 @@ const startCli = (): boolean | Promise<void> => {
196196
export class WrapperProcess {
197197
private process?: cp.ChildProcess;
198198
private started?: Promise<void>;
199+
private currentVersion = product.codeServerVersion;
199200

200201
public constructor() {
201202
ipcMain.onMessage(async (message) => {
202-
switch (message) {
203+
switch (message.type) {
203204
case "relaunch":
204-
logger.info("Relaunching...");
205+
logger.info(`Relaunching: ${this.currentVersion} -> ${message.version}`);
206+
this.currentVersion = message.version;
205207
this.started = undefined;
206208
if (this.process) {
207209
this.process.removeAllListeners();
@@ -233,10 +235,16 @@ export class WrapperProcess {
233235
}
234236

235237
private spawn(): cp.ChildProcess {
236-
return cp.spawn(process.argv[0], process.argv.slice(1), {
238+
// If we're using loose files then we need to specify the path. If we're in
239+
// the binary we need to let the binary determine the path (via nbin) since
240+
// it could be different between binaries which presents a problem when
241+
// upgrading (different version numbers or different staging directories).
242+
const isBinary = (global as any).NBIN_LOADED;
243+
return cp.spawn(process.argv[0], process.argv.slice(isBinary ? 2 : 1), {
237244
env: {
238245
...process.env,
239246
LAUNCH_VSCODE: "true",
247+
NBIN_BYPASS: undefined,
240248
VSCODE_PARENT_PID: process.pid.toString(),
241249
},
242250
stdio: ["inherit", "inherit", "inherit", "ipc"],

src/node/ipc.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ enum ControlMessage {
66
okFromChild = "ok<",
77
}
88

9-
export type Message = "relaunch";
9+
interface RelaunchMessage {
10+
type: "relaunch";
11+
version: string;
12+
}
13+
14+
export type Message = RelaunchMessage;
1015

1116
class IpcMain {
1217
protected readonly _onMessage = new Emitter<Message>();
@@ -41,11 +46,15 @@ class IpcMain {
4146
});
4247
}
4348

44-
public relaunch(): void {
49+
public relaunch(version: string): void {
50+
this.send({ type: "relaunch", version });
51+
}
52+
53+
private send(message: Message): void {
4554
if (!process.send) {
4655
throw new Error("Not a child process with IPC enabled");
4756
}
48-
process.send("relaunch");
57+
process.send(message);
4958
}
5059
}
5160

src/node/update.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { IFileService } from "vs/platform/files/common/files";
1313
import { ILogService } from "vs/platform/log/common/log";
1414
import product from "vs/platform/product/common/product";
1515
import { asJson, IRequestService } from "vs/platform/request/common/request";
16-
import { AvailableForDownload, State, UpdateType } from "vs/platform/update/common/update";
16+
import { AvailableForDownload, State, UpdateType, StateType } from "vs/platform/update/common/update";
1717
import { AbstractUpdateService } from "vs/platform/update/electron-main/abstractUpdateService";
1818
import { ipcMain } from "vs/server/src/node/ipc";
1919
import { extract } from "vs/server/src/node/marketplace";
@@ -62,7 +62,9 @@ export class UpdateService extends AbstractUpdateService {
6262
}
6363

6464
public async doQuitAndInstall(): Promise<void> {
65-
ipcMain.relaunch();
65+
if (this.state.type === StateType.Ready) {
66+
ipcMain.relaunch(this.state.update.version);
67+
}
6668
}
6769

6870
protected async doCheckForUpdates(context: any): Promise<void> {

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
resolved "https://registry.yarnpkg.com/@coder/logger/-/logger-1.1.8.tgz#416a7221d84161ee35eca9cfa93ba9377639b4ee"
88
integrity sha512-NJDC4rZTx0deVYqAxZtJWACq3IrVR59BjFeZebO3i7OfTZZMkkbLsGsCFMnJd5KnX6KjnvvFq4XXtwJ9yf8/YQ==
99

10-
"@coder/nbin@^1.2.2":
11-
version "1.2.2"
12-
resolved "https://registry.yarnpkg.com/@coder/nbin/-/nbin-1.2.2.tgz#c5f9aaa2a0e84c2a13a4cce895547efbd66730b7"
13-
integrity sha512-1Z6aYBRZRY1AQ2xp0jmoz+TXR8M4WaHa9FfVkOPej0KPJjYtEp18I+/6CmffDtBLxSnIai0rc+AA0VhbjCN/rg==
10+
"@coder/nbin@^1.2.3":
11+
version "1.2.3"
12+
resolved "https://registry.yarnpkg.com/@coder/nbin/-/nbin-1.2.3.tgz#793061abc7e1f7e0a9d1b9f854fa8f4121ed4e90"
13+
integrity sha512-JGJhkaqCrAF9hQ8e7m29/gbbKqDrBAOJCdjNZv9LKF+67lmHUoJ2QS+eHN+KOtpO4EJeEs4/uq7LSEdT+g3t5w==
1414
dependencies:
1515
"@coder/logger" "^1.1.8"
1616
fs-extra "^7.0.1"

0 commit comments

Comments
 (0)