diff --git a/lib/timers.js b/lib/timers.js index fdf38e8ef0a175..696df5a7ebb3e7 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -272,6 +272,10 @@ exports.setInterval = function(callback, repeat) { return timer; function wrapper() { + // If _repeat was overriden we are effectively canceled. Bail. + if (typeof timer._repeat !== 'function') + return; + timer._repeat(); // Do not re-arm unenroll'd or closed timers. diff --git a/test/parallel/test-timers-unenroll-unref-interval.js b/test/parallel/test-timers-unenroll-unref-interval.js index 2c8a6a385d2304..aade1c5b2e4e6e 100644 --- a/test/parallel/test-timers-unenroll-unref-interval.js +++ b/test/parallel/test-timers-unenroll-unref-interval.js @@ -1,6 +1,7 @@ 'use strict'; const common = require('../common'); +const assert = require('assert'); const timers = require('timers'); { @@ -33,6 +34,19 @@ const timers = require('timers'); }), 1).unref(); } +{ + const interval = setInterval(common.mustCall(() => { + // This case is only necessary / valid prior to + // c8c2544cd9c339cdde881fc9a7f0851971b94d72 + // which is not on the v4.x branch. + assert.strictEqual(typeof interval._repeat, 'function'); + + process.nextTick(common.mustCall(() => { + interval._repeat = null; + })); + }), 1).unref(); +} + // Use timers' intrinsic behavior to keep this open // exactly long enough for the problem to manifest. //