Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Fixes: #15068
  • Loading branch information
zhangzifa committed Oct 2, 2017
commit ba12e628e8dbc21349ac232ae96ba3fd9dfba60f
2 changes: 1 addition & 1 deletion lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function listOnTimeout() {
if (diff < msecs) {
var timeRemaining = msecs - (TimerWrap.now() - timer._idleStart);
if (timeRemaining < 0) {
timeRemaining = 0;
timeRemaining = 1;
}
this.start(timeRemaining);
debug('%d list wait because diff is %d', msecs, diff);
Expand Down
22 changes: 22 additions & 0 deletions test/sequential/test-timers-block-eventloop.js
Original file line number Diff line number Diff line change
@@ -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);