From f8f81bd214461a785ac882e5ec37af874920e08c Mon Sep 17 00:00:00 2001 From: Ian Patton Date: Fri, 16 May 2014 11:45:30 -0400 Subject: [PATCH 1/2] prevent crash when socket does not exist --- lib/receiver.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/receiver.js b/lib/receiver.js index c5363ab..9ce5581 100644 --- a/lib/receiver.js +++ b/lib/receiver.js @@ -30,7 +30,7 @@ Receiver.prototype.addSocket = function (socket) { }; Receiver.prototype.send = function (data) { - if (data.cmd === 'init') { + if (data.cmd === 'init' && this.sockets[data.args.socket]) { this.sockets[data.args.socket].emit('commands', [ data ]); return; } @@ -41,4 +41,4 @@ Receiver.prototype.send = function (data) { } }; -module.exports = Receiver; \ No newline at end of file +module.exports = Receiver; From f5a8f4b8f3186ede267f95c983d7b07559bb696b Mon Sep 17 00:00:00 2001 From: Ian Patton Date: Fri, 16 May 2014 13:00:37 -0400 Subject: [PATCH 2/2] Make observer die with parent process --- lib/look.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/look.js b/lib/look.js index bce0bc4..edda9e3 100644 --- a/lib/look.js +++ b/lib/look.js @@ -13,7 +13,7 @@ agentio.createClient = function () { module.exports.start = function (port, host) { if (cluster.isMaster) { - var observer = child_process.fork(__dirname + '/observer', [ port, host ]); + var observer = child_process.spawn('node', [__dirname + '/observer', port, host ], {stdio: ['ipc', process.stdout, process.stderr], detached: false}); observer.on('message', function (data) { if (data.cmd === 'init') { @@ -23,6 +23,7 @@ module.exports.start = function (port, host) { agent.request(data); clusterhub.emit('request', data); }); + observer.unref(); agent.on('request', function (data) { observer.send(data); @@ -56,4 +57,4 @@ module.exports.start = function (port, host) { }); nodetime.profile({ server: 'localhost', accountKey: 'session', silent: true, transactions: false }); -}; \ No newline at end of file +};