From 4ca52304021569d9695a006ee0335b49c86cf708 Mon Sep 17 00:00:00 2001 From: Simo Kinnunen Date: Mon, 17 Nov 2014 15:51:57 +0900 Subject: [PATCH] Unify socket closers. Don't put them all in one try-catch or some might remain. --- lib/units/notify/hipchat.js | 7 ++++++- lib/units/processor/index.js | 13 ++++++++----- lib/units/provider/index.js | 15 +++++++++------ lib/units/reaper/index.js | 4 +++- lib/units/triproxy/index.js | 14 ++++++++------ 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/lib/units/notify/hipchat.js b/lib/units/notify/hipchat.js index 3f909d47..79e0f084 100644 --- a/lib/units/notify/hipchat.js +++ b/lib/units/notify/hipchat.js @@ -72,6 +72,11 @@ module.exports = function(options) { logger.LevelLabel[options.priority]) lifecycle.observe(function() { - sub.close() + try { + sub.close() + } + catch (err) { + // No-op + } }) } diff --git a/lib/units/processor/index.js b/lib/units/processor/index.js index c931460a..b91b1d2c 100644 --- a/lib/units/processor/index.js +++ b/lib/units/processor/index.js @@ -161,10 +161,13 @@ module.exports = function(options) { .handler()) lifecycle.observe(function() { - try { - appDealer.close() - devDealer.close() - } - catch (err) {} + [appDealer, devDealer].forEach(function(sock) { + try { + sock.close() + } + catch (err) { + // No-op + } + }) }) } diff --git a/lib/units/provider/index.js b/lib/units/provider/index.js index 38d08d98..1a185121 100644 --- a/lib/units/provider/index.js +++ b/lib/units/provider/index.js @@ -394,13 +394,16 @@ module.exports = function(options) { })() lifecycle.observe(function() { - clearTimeout(totalsTimer) + [push, sub].forEach(function(sock) { + try { + sock.close() + } + catch (err) { + // No-op + } + }) - try { - push.close() - sub.close() - } - catch (err) {} + clearTimeout(totalsTimer) return Promise.all(Object.keys(workers).map(function(serial) { return workers[serial].cancel() diff --git a/lib/units/reaper/index.js b/lib/units/reaper/index.js index ce5fa5b5..b9561caa 100644 --- a/lib/units/reaper/index.js +++ b/lib/units/reaper/index.js @@ -53,6 +53,8 @@ module.exports = function(options) { try { push.close() } - catch (err) {} + catch (err) { + // No-op + } }) } diff --git a/lib/units/triproxy/index.js b/lib/units/triproxy/index.js index c6a2ff87..0d0112bf 100644 --- a/lib/units/triproxy/index.js +++ b/lib/units/triproxy/index.js @@ -34,11 +34,13 @@ module.exports = function(options) { log.info('PULL socket bound on', options.endpoints.pull) lifecycle.observe(function() { - try { - pub.close() - dealer.close() - pull.close() - } - catch (err) {} + [pub, dealer, pull].forEach(function(sock) { + try { + sock.close() + } + catch (err) { + // No-op + } + }) }) }