Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug/Timers being lost on shutdown due to a race condition in nats #25

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions lib/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,26 +201,33 @@ 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);
cb(err, null);
Iaskebba marked this conversation as resolved.
Show resolved Hide resolved
}
this.nats.publish('skyring:events', JSON.stringify({
type: EVENT_STATUS.CREATED
, timer: id
, node: this[kNode]
, created: data.created
, payload: payload
}), noop);

data.timer = setTimeout(
transport
, payload.timeout - elapsed
, payload.callback.method
, payload.callback.uri
, payload.data
, id
, this
).unref();
this.set( id, data );
cb(null, id);
}), (err) => {
if (err) {
console.error(err);
cb(err, null);
Iaskebba marked this conversation as resolved.
Show resolved Hide resolved
}
data.timer = setTimeout(
transport
, payload.timeout - elapsed
, payload.callback.method
, payload.callback.uri
, payload.data
, id
, this
).unref();
this.set(id, data);
cb(null, id);
});
Iaskebba marked this conversation as resolved.
Show resolved Hide resolved
});
}

Expand Down Expand Up @@ -418,13 +425,17 @@ timers.success('2e2f6dad-9678-4caf-bc41-8e62ca07d551', error)
}

disconnect(cb = noop) {
this[storage].close(noop)
this[storage].close(noop);
this.transports[shutdown](() => {
const client = this.nats;
this.nats.publish('skyring:node', JSON.stringify({
node: this[kNode]
, type: EVENT_STATUS.SHUTDOWN
}), noop)
setImmediate(this.nats.quit, cb)
}), function() {
client.flush(function() {
setImmediate(client.quit, cb);
});
});
esatterwhite marked this conversation as resolved.
Show resolved Hide resolved
});
}

Expand Down