Skip to content

Commit e647c5d

Browse files
zhangzifajasnell
authored andcommitted
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: #15072 Fixes: #15068 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent a078584 commit e647c5d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/timers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ function listOnTimeout() {
233233
if (diff < msecs) {
234234
var timeRemaining = msecs - (TimerWrap.now() - timer._idleStart);
235235
if (timeRemaining < 0) {
236-
timeRemaining = 0;
236+
timeRemaining = 1;
237237
}
238238
this.start(timeRemaining);
239239
debug('%d list wait because diff is %d', msecs, diff);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const fs = require('fs');
5+
6+
const t1 = setInterval(() => {
7+
common.busyLoop(12);
8+
}, 10);
9+
10+
const t2 = setInterval(() => {
11+
common.busyLoop(15);
12+
}, 10);
13+
14+
const t3 = setTimeout(common.mustNotCall('eventloop blocked!'), 100);
15+
16+
setTimeout(function() {
17+
fs.stat('./nonexistent.txt', (err, stats) => {
18+
clearInterval(t1);
19+
clearInterval(t2);
20+
clearTimeout(t3);
21+
});
22+
}, 50);

0 commit comments

Comments
 (0)