Skip to content

Commit 759e8fd

Browse files
Fishrock123MylesBorins
authored andcommitted
timers: bail from intervals if _repeat is bad
PR-URL: #10365 Ref: #9685 Reviewed-By: Myles Borins <myles.borins@gmail.com>
1 parent 553d95d commit 759e8fd

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/timers.js

+4
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ exports.setInterval = function(callback, repeat) {
272272
return timer;
273273

274274
function wrapper() {
275+
// If _repeat was overriden we are effectively canceled. Bail.
276+
if (typeof timer._repeat !== 'function')
277+
return;
278+
275279
timer._repeat();
276280

277281
// Do not re-arm unenroll'd or closed timers.

test/parallel/test-timers-unenroll-unref-interval.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const common = require('../common');
4+
const assert = require('assert');
45
const timers = require('timers');
56

67
{
@@ -33,6 +34,19 @@ const timers = require('timers');
3334
}), 1).unref();
3435
}
3536

37+
{
38+
const interval = setInterval(common.mustCall(() => {
39+
// This case is only necessary / valid prior to
40+
// c8c2544cd9c339cdde881fc9a7f0851971b94d72
41+
// which is not on the v4.x branch.
42+
assert.strictEqual(typeof interval._repeat, 'function');
43+
44+
process.nextTick(common.mustCall(() => {
45+
interval._repeat = null;
46+
}));
47+
}), 1).unref();
48+
}
49+
3650
// Use timers' intrinsic behavior to keep this open
3751
// exactly long enough for the problem to manifest.
3852
//

0 commit comments

Comments
 (0)