timers: fix eventloop block
When there are at least 2 timers set by setInterval whose callback execution are longer than interval, the eventloop will be blocked. This commit fix the above bug. PR-URL: https://github.com/nodejs/node/pull/15072 Fixes: https://github.com/nodejs/node/issues/15068 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
a0785845bf
commit
e647c5d7de
@ -233,7 +233,7 @@ function listOnTimeout() {
|
|||||||
if (diff < msecs) {
|
if (diff < msecs) {
|
||||||
var timeRemaining = msecs - (TimerWrap.now() - timer._idleStart);
|
var timeRemaining = msecs - (TimerWrap.now() - timer._idleStart);
|
||||||
if (timeRemaining < 0) {
|
if (timeRemaining < 0) {
|
||||||
timeRemaining = 0;
|
timeRemaining = 1;
|
||||||
}
|
}
|
||||||
this.start(timeRemaining);
|
this.start(timeRemaining);
|
||||||
debug('%d list wait because diff is %d', msecs, diff);
|
debug('%d list wait because diff is %d', msecs, diff);
|
||||||
|
22
test/sequential/test-timers-block-eventloop.js
Normal file
22
test/sequential/test-timers-block-eventloop.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const common = require('../common');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const t1 = setInterval(() => {
|
||||||
|
common.busyLoop(12);
|
||||||
|
}, 10);
|
||||||
|
|
||||||
|
const t2 = setInterval(() => {
|
||||||
|
common.busyLoop(15);
|
||||||
|
}, 10);
|
||||||
|
|
||||||
|
const t3 = setTimeout(common.mustNotCall('eventloop blocked!'), 100);
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
fs.stat('./nonexistent.txt', (err, stats) => {
|
||||||
|
clearInterval(t1);
|
||||||
|
clearInterval(t2);
|
||||||
|
clearTimeout(t3);
|
||||||
|
});
|
||||||
|
}, 50);
|
Loading…
x
Reference in New Issue
Block a user