From 8992db807d66554212889c3acd531a4361bf96fb Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Wed, 16 Nov 2016 00:48:29 +0000 Subject: [PATCH] fix(GUI): kill CLI processes when child writer dies (#855) Turns out that when the parent process gets SIGKILL, the children process would still remain alive. In order to mitigate this, we force the IPC client opened by the child writer to not attempt to reconnect to the IPC server if this one dies, so we can catch the "disconnect" event and kill the children as a result. Fixes: https://github.com/resin-io/etcher/issues/850 Change-Type: patch Changelog-Entry: Fix writing process remaining alive after the GUI is closed. Signed-off-by: Juan Cruz Viotti --- lib/src/child-writer/writer-proxy.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/src/child-writer/writer-proxy.js b/lib/src/child-writer/writer-proxy.js index 21bceacd..c8c4fd9c 100644 --- a/lib/src/child-writer/writer-proxy.js +++ b/lib/src/child-writer/writer-proxy.js @@ -139,10 +139,20 @@ return isElevated().then((elevated) => { return new Bluebird((resolve, reject) => { ipc.config.id = process.env.IPC_CLIENT_ID; ipc.config.silent = true; + + // > If set to 0, the client will NOT try to reconnect. + // See https://github.com/RIAEvangelist/node-ipc/ + // + // The purpose behind this change is for this process + // to emit a "disconnect" event as soon as the GUI + // process is closed, so we can kill the CLI as well. + ipc.config.stopRetrying = 0; + ipc.connectTo(process.env.IPC_SERVER_ID, () => { ipc.of[process.env.IPC_SERVER_ID].on('error', reject); ipc.of[process.env.IPC_SERVER_ID].on('connect', () => { const child = childProcess.spawn(EXECUTABLE, ETCHER_ARGUMENTS); + ipc.of[process.env.IPC_SERVER_ID].on('disconnect', _.bind(child.kill, child)); child.on('error', reject); child.on('close', resolve);