Skip to content

Commit

Permalink
timers: bail from intervals if _repeat is bad
Browse files Browse the repository at this point in the history
PR-URL: #10365
Ref: #9685

Reviewed-By: Myles Borins <myles.borins@gmail.com>
  • Loading branch information
Fishrock123 authored and MylesBorins committed Dec 21, 2016
1 parent 553d95d commit 759e8fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-timers-unenroll-unref-interval.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const timers = require('timers');

{
Expand Down Expand Up @@ -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.
//
Expand Down

0 comments on commit 759e8fd

Please sign in to comment.