From 0e7d3cbef8a745913efbe8f6886accccad4feec8 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 14 Sep 2017 12:11:07 +0200 Subject: [PATCH] fix hanging --wait processes --- src/vs/base/node/pfs.ts | 15 +++++++++++++++ src/vs/code/electron-main/launch.ts | 9 +++++++-- src/vs/code/node/cli.ts | 10 ++-------- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/vs/base/node/pfs.ts b/src/vs/base/node/pfs.ts index 16f8d7509be..ce1f52d799c 100644 --- a/src/vs/base/node/pfs.ts +++ b/src/vs/base/node/pfs.ts @@ -189,3 +189,18 @@ const tmpDir = os.tmpdir(); export function del(path: string, tmp = tmpDir): TPromise { return nfcall(extfs.del, path, tmp); } + +export function whenDeleted(path: string): TPromise { + + // Complete when wait marker file is deleted + return new TPromise(c => { + const interval = setInterval(() => { + fs.exists(path, exists => { + if (!exists) { + clearInterval(interval); + c(null); + } + }); + }, 1000); + }); +} \ No newline at end of file diff --git a/src/vs/code/electron-main/launch.ts b/src/vs/code/electron-main/launch.ts index 1df7365dc64..189224ef9c6 100644 --- a/src/vs/code/electron-main/launch.ts +++ b/src/vs/code/electron-main/launch.ts @@ -14,6 +14,7 @@ import { ParsedArgs } from 'vs/platform/environment/common/environment'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { OpenContext } from 'vs/platform/windows/common/windows'; import { IWindowsMainService, ICodeWindow } from 'vs/platform/windows/electron-main/windows'; +import { whenDeleted } from 'vs/base/node/pfs'; export const ID = 'launchService'; export const ILaunchService = createDecorator(ID); @@ -113,9 +114,13 @@ export class LaunchService implements ILaunchService { } // If the other instance is waiting to be killed, we hook up a window listener if one window - // is being used and only then resolve the startup promise which will kill this second instance + // is being used and only then resolve the startup promise which will kill this second instance. + // In addition, we poll for the wait marker file to be deleted to return. if (args.wait && usedWindows.length === 1 && usedWindows[0]) { - return this.windowsService.waitForWindowCloseOrLoad(usedWindows[0].id); + return TPromise.any([ + this.windowsService.waitForWindowCloseOrLoad(usedWindows[0].id), + whenDeleted(args.waitMarkerFilePath) + ]).then(() => void 0, () => void 0); } return TPromise.as(null); diff --git a/src/vs/code/node/cli.ts b/src/vs/code/node/cli.ts index d0f0416e6ff..7476115fcee 100644 --- a/src/vs/code/node/cli.ts +++ b/src/vs/code/node/cli.ts @@ -14,6 +14,7 @@ import pkg from 'vs/platform/node/package'; import * as fs from 'fs'; import * as paths from 'path'; import * as os from 'os'; +import { whenDeleted } from 'vs/base/node/pfs'; function shouldSpawnCliProcess(argv: ParsedArgs): boolean { return argv['list-extensions'] || !!argv['install-extension'] || !!argv['uninstall-extension']; @@ -105,14 +106,7 @@ export function main(argv: string[]): TPromise { child.once('exit', () => c(null)); // Complete when wait marker file is deleted - const interval = setInterval(() => { - fs.exists(waitMarkerFilePath, exists => { - if (!exists) { - clearInterval(interval); - c(null); - } - }); - }, 1000); + whenDeleted(waitMarkerFilePath).done(c, c); }); } }