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.
pull/24503/head
Ben Noordhuis 2012-08-17 14:11:33 +02:00
parent 05b3f88064
commit 6c999fd285
1 changed files with 3 additions and 1 deletions

View File

@ -253,10 +253,12 @@ var Timeout = function(after) {
Timeout.prototype.unref = function() { Timeout.prototype.unref = function() {
if (!this._handle) { if (!this._handle) {
var delay = this._when - Date.now();
if (delay < 0) delay = 0;
exports.unenroll(this); exports.unenroll(this);
this._handle = new Timer(); this._handle = new Timer();
this._handle.ontimeout = this._onTimeout; 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.domain = this.domain;
this._handle.unref(); this._handle.unref();
} else { } else {