diff --git a/lib/timers.js b/lib/timers.js index 897b64f9124..d281ea40615 100644 --- a/lib/timers.js +++ b/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 {