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 <jviotti@openmailbox.org>
This commit is contained in:
Juan Cruz Viotti 2016-11-16 00:48:29 +00:00 committed by GitHub
parent b4f1d82a51
commit 8992db807d

View File

@ -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);