Calculation of poll phase timeout ignores setTimeout() if it is set after promise resolving inside another setTimeout()
If I run the script below, timeouts after Promise.resolve() are ignored while calculation timeout for the poll phase if the queue is empty.
The timeout callbacks declared inside then body of Promise.resolve() will be called if anything else will stop poll waiting (for example, another setTimeout).
However, their timeout values will have no impact on the poll phase timeout.
const getCurrentTime = function () {
const today = new Date();
return `${today.getHours()}:${today.getMinutes()}:${today.getSeconds()}:${today.getMilliseconds()}`;
}
console.info(`${getCurrentTime()}|Start`);
// global timeout
setTimeout(() => {
console.info(`${getCurrentTime()}|5s-timeout ended`);
}, 5000);
setTimeout(() => {
Promise.resolve().then(() => {
console.info(`${getCurrentTime()}|Promise has been resolved`);
const timerStartTime = process.hrtime();
// The callback will be run after the global timeout
setTimeout(() => {
const timeoutActualStart = process.hrtime(timerStartTime);
console.info(`${getCurrentTime()}|0ms-timeout started after ${timeoutActualStart}s`);
});
// The callback will be run after the global timeout
setTimeout(() => {
const timeoutActualStart = process.hrtime(timerStartTime);
console.info(`${getCurrentTime()}|1s-timeout started after ${timeoutActualStart}s`);
}, 1000);
});
});
The issue can be only reproduced while using electron with ELECTRON_RUN_AS_NODE activated. The issue cannot be reproduced if I run the same script using nodejs v12.13.0. Electron version on my PC is v8.0.0 (originally the issue was reproduced on v7.1.11).
| Electron/node output (incorrect execution) | Node output (correct execution) |
|---|---|
| Start | Start |
| Promise has been resolved | Promise has been resolved |
| 0ms-timeout started after 4,999303964s | 0ms-timeout started after 0,1527468s |
| 1s-timeout started after 5,254293s | 1s-timeout started after 1,990436s |
| 5s-timeout ended | 5s-timeout ended |
Hi! Any updates on this one? Any eyes looking on the issue?