From 01c4079e9fd9f5730e343dc59beb4dbb86ec031f Mon Sep 17 00:00:00 2001 From: Ari <149393150+A21-devs@users.noreply.github.com> Date: Fri, 4 Dec 2026 13:58:39 -0500 Subject: [PATCH 1/3] waitForExit: drop its exit listener when the wait times out The same process can be waited on more than once (the quit flow is about to wait another minute at the user's request), and every timed-out wait left an 'exit' listener on the child process, which trips Node's max listeners warning after ten of them. --- src/main/vmRunner.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/vmRunner.ts b/src/main/vmRunner.ts index 6a32eea..6b72a75 100644 --- a/src/main/vmRunner.ts +++ b/src/main/vmRunner.ts @@ -284,11 +284,17 @@ export class VmRunner extends EventEmitter { const r = this.running.get(name) if (!r) return Promise.resolve(true) return new Promise((resolve) => { - const t = setTimeout(() => resolve(false), timeoutMs) - r.proc.once('exit', () => { + const onExit = (): void => { clearTimeout(t) resolve(true) - }) + } + const t = setTimeout(() => { + // the process can outlive several waits (the quit flow asks and waits again), and a + // listener left behind for each of them trips Node's max listeners warning + r.proc.off('exit', onExit) + resolve(false) + }, timeoutMs) + r.proc.once('exit', onExit) }) } From 76ba0006db00e02a259560cf0d7bdf471bf7a362 Mon Sep 17 00:00:00 2001 From: Ari <149393150+A21-devs@users.noreply.github.com> Date: Fri, 4 Dec 2026 13:58:40 -0500 Subject: [PATCH 2/3] Shut down and quit: offer another minute instead of only Force off A minute after the power button press, any guest still running got a question with Force off and Cancel. A Windows guest installing updates on shutdown, or a Linux guest with a slow service, regularly needs longer than that, and Force off at that point loses the update. The question now offers Wait another minute, which is the default button, and says how long the app has been waiting. Cancel still stops the quit. The window goes back to the tray while it waits. --- src/main/index.ts | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 3030dc2..7c1e457 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -381,16 +381,36 @@ async function shutDownAllAndQuit(): Promise { } }) ) - const done = await Promise.all(names.map((n) => runner.waitForExit(n, 60_000))) - const stuck = names.filter((_n, i) => !done[i]) - if (stuck.length) { + if (!(await waitForShutdown(names))) return + quitting = true + app.quit() +} + +const FORCE = 'Force off and quit' +const MORE = 'Wait another minute' +const MINUTE = 60_000 + +/** + * Waits a minute for each guest, then asks about the ones still up. True to go on with the quit, + * false if the user cancelled. A Windows guest installing updates on shutdown regularly needs + * longer than a minute, so the question offers another minute as well as Force off. + */ +async function waitForShutdown(names: string[]): Promise { + const runner = backend!.runner + let waiting = names + for (let minutes = 1; ; minutes++) { + const done = await Promise.all(waiting.map((n) => runner.waitForExit(n, MINUTE))) + waiting = waiting.filter((_n, i) => !done[i]) + if (!waiting.length) return true const opts = { type: 'warning' as const, title: 'Still running', - message: `${stuck.join(', ')} did not shut down within a minute.`, - detail: 'Force off loses anything unsaved inside the guest.', - buttons: ['Force off and quit', 'Cancel'], - cancelId: 1, + message: `${waiting.join(', ')} ${waiting.length === 1 ? 'has' : 'have'} not shut down ${minutes === 1 ? 'within a minute' : `in ${minutes} minutes`}.`, + detail: + 'A guest installing updates on shutdown can take a few minutes. Force off loses anything unsaved inside it.', + buttons: [MORE, FORCE, 'Cancel'], + cancelId: 2, + defaultId: 0, noLink: true } showWindow() @@ -402,14 +422,16 @@ async function shutDownAllAndQuit(): Promise { } finally { askingAboutVms = false } - if (r.response !== 0) { + const choice = opts.buttons[r.response] + if (choice === FORCE) return true + if (choice !== MORE) { shuttingDown = false updateTrayMenu() - return + return false } + // back out of the way for the next minute, the tray already says what the app is waiting for + hideToTray(false) } - quitting = true - app.quit() } app.on('second-instance', showWindow) From 1ea94beb8d4d68b4c585cc7530a6605a903de57f Mon Sep 17 00:00:00 2001 From: Ari <149393150+A21-devs@users.noreply.github.com> Date: Fri, 4 Dec 2026 14:00:27 -0500 Subject: [PATCH 3/3] Count the real wait, and say them for more than one VM The question's minute count came from the number of rounds, so a question left open for a while made it read short. Take it from a timestamp instead, and make the detail line agree with the number of VMs named above it. --- src/main/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 7c1e457..282f3f1 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -398,16 +398,18 @@ const MINUTE = 60_000 async function waitForShutdown(names: string[]): Promise { const runner = backend!.runner let waiting = names - for (let minutes = 1; ; minutes++) { + // real time, not rounds of the question: it counts a question left unanswered for a while too + const since = Date.now() + for (;;) { const done = await Promise.all(waiting.map((n) => runner.waitForExit(n, MINUTE))) waiting = waiting.filter((_n, i) => !done[i]) if (!waiting.length) return true + const minutes = Math.max(1, Math.round((Date.now() - since) / MINUTE)) const opts = { type: 'warning' as const, title: 'Still running', message: `${waiting.join(', ')} ${waiting.length === 1 ? 'has' : 'have'} not shut down ${minutes === 1 ? 'within a minute' : `in ${minutes} minutes`}.`, - detail: - 'A guest installing updates on shutdown can take a few minutes. Force off loses anything unsaved inside it.', + detail: `A guest installing updates on shutdown can take a few minutes. Force off loses anything unsaved inside ${waiting.length === 1 ? 'it' : 'them'}.`, buttons: [MORE, FORCE, 'Cancel'], cancelId: 2, defaultId: 0,