From 1b0280671c25c427e9921ac3d4f3e5b4e40276b6 Mon Sep 17 00:00:00 2001 From: Ian Skebba Date: Fri, 21 Dec 2018 22:59:48 -0800 Subject: [PATCH] timers being lost on shutdown due to a race condition in nats (#25) * bug/Timers being lost on shutdown due to a race condition in nats * Adjusted PR to prevent double callback and reverted change to creation * Adjusted PR for double callback * fixing some whitespace --- lib/timer.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/timer.js b/lib/timer.js index 43cef31f..7e3e0245 100644 --- a/lib/timer.js +++ b/lib/timer.js @@ -201,16 +201,19 @@ timers.create(id, options, (err) => { debug('setting timer', id); //TODO(esatterwhite): // what should happen if leveldb fails. - if (err) console.error(err); + if (err) { + console.error(err); + return cb(err, null); + } this.nats.publish('skyring:events', JSON.stringify({ type: EVENT_STATUS.CREATED , timer: id , node: this[kNode] , created: data.created , payload: payload - }), noop); + }), noop); - data.timer = setTimeout( + data.timer = setTimeout( transport , payload.timeout - elapsed , payload.callback.method @@ -418,7 +421,7 @@ timers.failure('2e2f6dad-9678-4caf-bc41-8e62ca07d551', error) } disconnect(cb = noop) { - this[storage].close(noop) + this[storage].close(noop); this.transports[shutdown](() => { this.nats.publish('skyring:node', JSON.stringify({ node: this[kNode]