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

Prevent timeout value from skirting limit check #3536

Merged
merged 8 commits into from
Nov 9, 2018
26 changes: 19 additions & 7 deletions lib/runnable.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,35 @@ function Runnable(title, fn) {
utils.inherits(Runnable, EventEmitter);

/**
* Set & get timeout `ms`.
* Get current timeout value in msecs.
*
* @api private
* @param {number|string} ms
* @return {Runnable|number} ms or Runnable instance.
* @private
* @returns {number} current timeout threshold value
*/
/**
* @summary
* Set timeout threshold value (msecs).
*
* @description
* A string argument can use shorthand (such as "2s") and will be converted.
* If the value is `0` or exceeds `2^<sup>31</sup>`, timeouts will be disabled.
*
* @private
* @param {number|string} ms - Timeout threshold value.
* @returns {Runnable} this
* @chainable
*/
Runnable.prototype.timeout = function(ms) {
if (!arguments.length) {
return this._timeout;
}
if (typeof ms === 'string') {
ms = milliseconds(ms);
}
// see #1652 for reasoning
if (ms === 0 || ms > Math.pow(2, 31)) {
this._enableTimeouts = false;
}
if (typeof ms === 'string') {
ms = milliseconds(ms);
}
debug('timeout %d', ms);
this._timeout = ms;
if (this.timer) {
Expand Down