diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/utils.js | 5 | ||||
-rw-r--r-- | src/webTorrentNode.js | 21 | ||||
-rw-r--r-- | src/webtorrent.js | 4 |
3 files changed, 21 insertions, 9 deletions
diff --git a/src/utils.js b/src/utils.js index 7a5c7b7ea..8ce1789f9 100644 --- a/src/utils.js +++ b/src/utils.js | |||
@@ -186,5 +186,10 @@ | |||
186 | return dec | 186 | return dec |
187 | } | 187 | } |
188 | 188 | ||
189 | utils.cleanForExit = function (webtorrent_process) { | ||
190 | logger.info('Gracefully exiting') | ||
191 | process.kill(-webtorrent_process.pid) | ||
192 | } | ||
193 | |||
189 | module.exports = utils | 194 | module.exports = utils |
190 | })() | 195 | })() |
diff --git a/src/webTorrentNode.js b/src/webTorrentNode.js index ebe8d5d81..507cf31fc 100644 --- a/src/webTorrentNode.js +++ b/src/webTorrentNode.js | |||
@@ -43,11 +43,23 @@ | |||
43 | ipc.serve(function () { | 43 | ipc.serve(function () { |
44 | if (!webtorrentnode.silent) logger.info('IPC server ready.') | 44 | if (!webtorrentnode.silent) logger.info('IPC server ready.') |
45 | 45 | ||
46 | // Run a timeout of 30s after which we exit the process | ||
47 | var timeout_webtorrent_process = setTimeout(function () { | ||
48 | logger.error('Timeout : cannot run the webtorrent process. Please ensure you have electron-prebuilt npm package installed with xvfb-run.') | ||
49 | process.exit() | ||
50 | }, 30000) | ||
51 | |||
46 | ipc.server.on(processKey + '.ready', function () { | 52 | ipc.server.on(processKey + '.ready', function () { |
47 | if (!webtorrentnode.silent) logger.info('Webtorrent process ready.') | 53 | if (!webtorrentnode.silent) logger.info('Webtorrent process ready.') |
54 | clearTimeout(timeout_webtorrent_process) | ||
48 | callback() | 55 | callback() |
49 | }) | 56 | }) |
50 | 57 | ||
58 | ipc.server.on(processKey + '.exception', function (data) { | ||
59 | logger.error('Received exception error from webtorrent process.', { exception: data.exception }) | ||
60 | process.exit() | ||
61 | }) | ||
62 | |||
51 | var webtorrent_process = spawn(__dirname + '/webtorrent.js', host, port, { detached: true }) | 63 | var webtorrent_process = spawn(__dirname + '/webtorrent.js', host, port, { detached: true }) |
52 | webtorrent_process.stderr.on('data', function (data) { | 64 | webtorrent_process.stderr.on('data', function (data) { |
53 | // logger.debug('Webtorrent process stderr: ', data.toString()) | 65 | // logger.debug('Webtorrent process stderr: ', data.toString()) |
@@ -57,15 +69,6 @@ | |||
57 | // logger.debug('Webtorrent process:', data.toString()) | 69 | // logger.debug('Webtorrent process:', data.toString()) |
58 | }) | 70 | }) |
59 | 71 | ||
60 | function exitChildProcess () { | ||
61 | if (!webtorrentnode.silent) logger.info('Gracefully exit child') | ||
62 | process.kill(-webtorrent_process.pid) | ||
63 | process.exit(0) | ||
64 | } | ||
65 | |||
66 | process.on('SIGINT', exitChildProcess) | ||
67 | process.on('SIGTERM', exitChildProcess) | ||
68 | |||
69 | webtorrentnode.app = webtorrent_process | 72 | webtorrentnode.app = webtorrent_process |
70 | }) | 73 | }) |
71 | 74 | ||
diff --git a/src/webtorrent.js b/src/webtorrent.js index 840f97671..18ae6b6ba 100644 --- a/src/webtorrent.js +++ b/src/webtorrent.js | |||
@@ -83,5 +83,9 @@ | |||
83 | ipc.of[nodeKey].emit(processKey + '.ready') | 83 | ipc.of[nodeKey].emit(processKey + '.ready') |
84 | console.log('Ready.') | 84 | console.log('Ready.') |
85 | }) | 85 | }) |
86 | |||
87 | process.on('uncaughtException', function (e) { | ||
88 | ipc.of[nodeKey].emit(processKey + '.exception', { exception: e }) | ||
89 | }) | ||
86 | } | 90 | } |
87 | })() | 91 | })() |