Skip to content

Commit bb81390

Browse files
zhangzifaMylesBorins
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 <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>
1 parent ab580c3 commit bb81390

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
@@ -183,7 +183,7 @@ function listOnTimeout() {
183183
if (diff < msecs) {
184184
var timeRemaining = msecs - (TimerWrap.now() - timer._idleStart);
185185
if (timeRemaining < 0) {
186-
timeRemaining = 0;
186+
timeRemaining = 1;
187187
}
188188
this.start(timeRemaining);
189189
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)