-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Race conditions between setTimeout() & setImmediate() #48163
Copy link
Copy link
Closed as not planned
Labels
flaky-testIssues and PRs involving tests that fail intermittently in CI.Issues and PRs involving tests that fail intermittently in CI.linuxIssues and PRs related to the Linux platform.Issues and PRs related to the Linux platform.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
Description
Activity
Metadata
Metadata
Assignees
Labels
flaky-testIssues and PRs involving tests that fail intermittently in CI.Issues and PRs involving tests that fail intermittently in CI.linuxIssues and PRs related to the Linux platform.Issues and PRs related to the Linux platform.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
Test
test-timers-immediate-queue.js
Platform
Linux x64
Console output
Build links
Additional information
This seems to be some kinda potential race condition between
setTimeout()andsetImmediate()?For the following code, it seems
TIMEOUTorIMMEDIATEeither could be printed first, since over a few runs the order will flip.However on my machine, the following code will always result in
TIMEOUTbeing printed first - the while loop strategy is what the test usesI was wondering: is it possible due to some conditions on the host system, for
IMMEDIATEto print beforeTIMEOUTin the second case?I do not know much about the Event Loop internals, but from some rough reading,
setTimeout()will put calbacks in the timers queue,setImmediate()in the I/O queue, and the timers are always checked first (https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick)But if in the first case (
setTimeoutwithout while waiting loop) it is non-predictable, I wonder if there are other factors at play, which make the test flaky.