Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ function rearm(timer) {

const clearTimeout = exports.clearTimeout = function(timer) {
if (timer && (timer[kOnTimeout] || timer._onTimeout)) {
timer._repeat = null;
timer[kOnTimeout] = timer._onTimeout = null;
if (timer instanceof Timeout) {
timer.close(); // for after === 0
Expand Down Expand Up @@ -444,7 +445,6 @@ function createRepeatTimeout(callback, repeat, args) {

exports.clearInterval = function(timer) {
if (timer && timer._repeat) {
timer._repeat = null;
clearTimeout(timer);
}
};
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-timers-cleartimeout-unref-interval.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';
const common = require('../common');
const timeout = setTimeout(common.fail, 2 ** 30); // Keep event loop open.
const interval = setInterval(common.mustCall(() => {
// Use clearTimeout() instead of clearInterval().
// The interval should still be cleared.
clearTimeout(interval);
setImmediate(() => { clearTimeout(timeout); });
}), 1).unref();