Permalink
Browse files

timers: fix assertion in Timeout.unref()

Ensure that the delay >= 0 when detaching the timer from the queue. Fixes the
following assertion:

  uv_timer_start: Assertion `timeout >= 0' failed.

No test included, it's timing sensitive.
  • Loading branch information...
1 parent 05b3f88 commit 6c999fd2855f9bccf99666431cddc9b34930720b @bnoordhuis bnoordhuis committed Aug 17, 2012
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/timers.js
View
4 lib/timers.js
@@ -253,10 +253,12 @@ var Timeout = function(after) {
Timeout.prototype.unref = function() {
if (!this._handle) {
+ var delay = this._when - Date.now();
+ if (delay < 0) delay = 0;
exports.unenroll(this);
this._handle = new Timer();
this._handle.ontimeout = this._onTimeout;
- this._handle.start(this._when - Date.now(), 0);
+ this._handle.start(delay, 0);
this._handle.domain = this.domain;
this._handle.unref();
} else {

2 comments on commit 6c999fd

@indutny
Node.js Foundation member

So you think that Date.now() is not always monotonic?

@bnoordhuis
Node.js Foundation member

Read carefully, Fedor: the issue was that this._when < Date.now() (by one or two units).

Please sign in to comment.