From a395fbb5507fb0bf2a8c5ef1657a49be9e9a7808 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 26 Jan 2018 14:32:40 +0100 Subject: [PATCH 1/2] added better error handling for child processes -> shutting down --- app/src/main/index.js | 6 ++++-- tasks/testnet.js | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/index.js b/app/src/main/index.js index e9867791e3..69c862eb9c 100644 --- a/app/src/main/index.js +++ b/app/src/main/index.js @@ -164,8 +164,10 @@ function startProcess (name, args, env) { child.on('exit', (code) => !shuttingDown && log(`${name} exited with code ${code}`)) child.on('error', function (err) { if (!(shuttingDown && err.code === 'ECONNRESET')) { - // Ignore ECONNRESET and re throw anything else - throw err + // if we throw errors here, they are not handled by the main process + console.error('[Uncaught Exception] Child', name, 'produced an unhandled exception:', err) + console.log('Shutting down UI') + shutdown() } }) return child diff --git a/tasks/testnet.js b/tasks/testnet.js index 748c6f465f..44e651cc09 100644 --- a/tasks/testnet.js +++ b/tasks/testnet.js @@ -39,4 +39,6 @@ async function main () { } } -main().catch(function (err) { throw err }) +main().catch(function (err) { + console.error('Starting the application failed', err) +}) From c7e8ba1a1993c7d3dda9d9333245c63b0829e3c3 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 26 Jan 2018 17:15:15 +0100 Subject: [PATCH 2/2] added windows specific child process kill --- package.json | 3 +-- tasks/runner.js | 26 +++++++++++++++++++++----- yarn.lock | 23 ----------------------- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 5aaea8c3a6..edbbafd346 100644 --- a/package.json +++ b/package.json @@ -113,9 +113,8 @@ "flatpickr": "^4.1.2", "fs-extra": "^5.0.0", "glob": "^7.1.2", - "jszip": "^3.1.5", "interactjs": "^1.3.3", - "kill-port": "^1.0.0", + "jszip": "^3.1.5", "moment": "^2.17.1", "mousetrap": "^1.6.1", "nib": "^1.1.2", diff --git a/tasks/runner.js b/tasks/runner.js index 400d584218..dc213d7690 100644 --- a/tasks/runner.js +++ b/tasks/runner.js @@ -3,7 +3,6 @@ const config = require('../config') const spawn = require('child_process').spawn const path = require('path') -const killPort = require('kill-port') let YELLOW = '\x1b[33m' let BLUE = '\x1b[34m' @@ -12,6 +11,24 @@ let END = '\x1b[0m' let NPM_BIN = path.join(path.dirname(__dirname), 'node_modules', '.bin') let PATH = `${NPM_BIN}:${process.env.PATH}` +// on windows some processes are not exiting when using child.kill so we use a windows specific comand +function cleanExitChild (child) { + return new Promise((resolve, reject) => { + var isWin = /^win/.test(process.platform) + if (!isWin) { + child.kill('SIGTERM') + } else { + var cp = require('child_process') + cp.exec('taskkill /PID ' + child.pid + ' /T /F', function (error, stdout, stderr) { + if (error !== null) { + console.log('exec error: ' + error) + } + }) + } + child.on('exit', resolve) + }) +} + function format (command, data, color) { return color + command + END + ' ' + // Two space offset @@ -31,7 +48,6 @@ function run (command, color, name, env) { child.on('exit', code => { console.log('exited', command, code) }) - process.on('exit', () => child.kill('SIGKILL')) return child } @@ -49,7 +65,7 @@ function startRendererServer () { } module.exports = async function (networkPath) { - await startRendererServer() + let renderProcess = await startRendererServer() console.log(`${BLUE}Starting electron...\n (network path: ${networkPath})\n${END}`) let env = Object.assign({}, { @@ -59,9 +75,9 @@ module.exports = async function (networkPath) { let mainProcess = run('electron app/src/main/index.dev.js', BLUE, 'electron', env) // terminate running processes on exit of main process - mainProcess.on('exit', code => { + mainProcess.on('exit', async code => { + await cleanExitChild(renderProcess) // webpack-dev-server spins up an own process we have no access to. so we kill all processes on our port - killPort(config.port) process.exit(0) }) } diff --git a/yarn.lock b/yarn.lock index d1bf642011..ffadf995ea 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2787,18 +2787,6 @@ exec-sh@^0.2.0: dependencies: merge "^1.1.3" -execa@^0.6.3: - version "0.6.3" - resolved "https://registry.yarnpkg.com/execa/-/execa-0.6.3.tgz#57b69a594f081759c69e5370f0d17b9cb11658fe" - dependencies: - cross-spawn "^5.0.1" - get-stream "^3.0.0" - is-stream "^1.1.0" - npm-run-path "^2.0.0" - p-finally "^1.0.0" - signal-exit "^3.0.0" - strip-eof "^1.0.0" - execa@^0.7.0: version "0.7.0" resolved "https://registry.yarnpkg.com/execa/-/execa-0.7.0.tgz#944becd34cc41ee32a63a9faf27ad5a65fc59777" @@ -3273,10 +3261,6 @@ get-stream@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14" -get-them-args@^1.2.1: - version "1.3.1" - resolved "https://registry.yarnpkg.com/get-them-args/-/get-them-args-1.3.1.tgz#ac1aeca013fda7db12591aaac129c58118e3daa8" - getpass@^0.1.1: version "0.1.7" resolved "https://registry.yarnpkg.com/getpass/-/getpass-0.1.7.tgz#5eff8e3e684d569ae4cb2b1282604e8ba62149fa" @@ -4576,13 +4560,6 @@ keyboardevents-areequal@^0.2.1: version "0.2.2" resolved "https://registry.yarnpkg.com/keyboardevents-areequal/-/keyboardevents-areequal-0.2.2.tgz#88191ec738ce9f7591c25e9056de928b40277194" -kill-port@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/kill-port/-/kill-port-1.0.0.tgz#b2c48d3048ea800d6620ff0d4b6f8ce91f644275" - dependencies: - execa "^0.6.3" - get-them-args "^1.2.1" - killable@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/killable/-/killable-1.0.0.tgz#da8b84bd47de5395878f95d64d02f2449fe05e6b"