diff --git a/lib/internal/timers.js b/lib/internal/timers.js index 8ba7923e57218e..5933c99a7cd06d 100644 --- a/lib/internal/timers.js +++ b/lib/internal/timers.js @@ -190,7 +190,8 @@ Timeout.prototype[inspect.custom] = function(_, options) { }; Timeout.prototype.refresh = function() { - if (this[kRefed]) + // Timers that are active or have been invoked. + if (this[kRefed] || this[kRefed] === null) active(this); else unrefActive(this); diff --git a/test/parallel/test-timers-refresh-called.js b/test/parallel/test-timers-refresh-called.js new file mode 100644 index 00000000000000..70e6afc4db1920 --- /dev/null +++ b/test/parallel/test-timers-refresh-called.js @@ -0,0 +1,12 @@ +'use strict'; + +const common = require('../common'); + +// Check only timer reactivated by `.refresh()` is in loop, +// only the timer is still active. + +const timer = setTimeout(common.mustCall(() => {}, 2), 1); + +setTimeout(() => { + timer.refresh(); +}, 1);