You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The behavior of console.log() in code (such as the while loop in your example) that never relinquishes control to the event loop (especially when piped to another process) in Node.js is a longstanding...uh...quirk. It's a lot harder to fix than you might think. Here's the relevant issue in the tracker: #6379
Or more specifically on the whole handling-when-piped-to-another-process issue: #1741
You can work around the issue by restructuring the code to relinquish control to the event loop. Here is one possibility.
Version
v16.13.1
Platform
Linux Ubuntu-ROG 5.15.0-47-generic #51-Ubuntu SMP Thu Aug 11 07:51:15 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
I'm using
fake-words
module (npm install fake-words
) with the following simple code:When I run
./genwords.js
, everything works as expected.However when I pipe into external program (on Ubuntu shell), the generation of words stops after a second.
How often does it reproduce? Is there a required condition?
Always, on Linux and macOS, but not on Windows.
What is the expected behavior?
console.log printing lines constantly.
What do you see instead?
Nothing. Printing stops after a second.
Additional information
I've posted a question here, but this seems more like a bug.
The text was updated successfully, but these errors were encountered: