Skip to content

Commit

Permalink
timers being lost on shutdown due to a race condition in nats (#25)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Ian Skebba authored and esatterwhite committed Dec 22, 2018
1 parent e7c61eb commit 1b02806
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 1b02806

Please sign in to comment.