mirror of
https://github.com/nodejs/node.git
synced 2025-05-14 21:36:02 +00:00

When an interval takes as long or longer to run as its timeout setting and the roundtrip from rearm() to its deferal takes exactly 1ms, that interval can then block the event loop. This is an edge case of another recently fixed bug (which in itself was an edge case). PR-URL: https://github.com/nodejs/node/pull/18486 Refs: https://github.com/nodejs/node/pull/15072 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
25 lines
582 B
JavaScript
25 lines
582 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const Timer = process.binding('timer_wrap').Timer;
|
|
const assert = require('assert');
|
|
|
|
let cntr = 0;
|
|
let first;
|
|
const t = setInterval(() => {
|
|
cntr++;
|
|
if (cntr === 1) {
|
|
common.busyLoop(100);
|
|
// ensure that the event loop passes before the second interval
|
|
setImmediate(() => assert.strictEqual(cntr, 1));
|
|
first = Timer.now();
|
|
} else if (cntr === 2) {
|
|
assert(Timer.now() - first < 100);
|
|
clearInterval(t);
|
|
}
|
|
}, 100);
|
|
const t2 = setInterval(() => {
|
|
if (cntr === 2) {
|
|
clearInterval(t2);
|
|
}
|
|
}, 100);
|