diff --git a/lib/timers.js b/lib/timers.js index 9d32aed7a592b3..0444b3de1cc64e 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -233,7 +233,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); diff --git a/test/sequential/test-timers-block-eventloop.js b/test/sequential/test-timers-block-eventloop.js new file mode 100644 index 00000000000000..210cf0d80a1127 --- /dev/null +++ b/test/sequential/test-timers-block-eventloop.js @@ -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);