-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
awaiting between creating a readline interface, and using async iterator will cause iterator to sometimes skip. #33463
Comments
readline isn't a stream, if you don't attach a handler you will miss events. that being said, exposing an async iterable doesn't make that very clear. |
As @devsnek outlined there's nothing actually wrong with the behavior. We might want to improve our docs when it comes to that? |
Similar problem shown here: https://stackoverflow.com/questions/62885667/why-does-this-readline-async-iterator-not-work-properly. I see only this output in the console:
The for await (const line1 of rl1) loop never goes into the for loop - it just skips right over it:
|
So, there is no intent to ever actually "fix" this. You're just going to document it as is and leave it that way forever? So, no asynchronous operations are permitted between creating the interface and consuming the async iterator to read the lines? What if you're trying to use this along with some other asynchronous stuff together? That's just a busted implementation IMO. Documenting the existing behavior is OK for a stop-gap, but not really OK for just sweeping the issue under the rug forever. |
@nodejs/readline Should this be re-opened? |
Fixes: #33463 PR-URL: #34675 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Rich Trott <[email protected]>
I agree with @jfriend00. This behaves like an improper implementation. Even after following the guidelines to prevent loss of line data, we are facing issues where have a function that is doing some heavy async operations on the result of each line (i.e. each line may take 5 or minutes to complete) and what we get is readline running some lines and eventually hanging and not issuing any more lines -> the program hangs forever.
|
Beforehand the async iterator for readline was created lazily when the stream was accessed which meant no events were buffered. In addition stream handling was modernized and improved in the process to support backpressure correctly. A test was added to assert this. Fixes: nodejs#28565 Fixes: nodejs#33463
Fixes: #33463 PR-URL: #34675 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Rich Trott <[email protected]>
readline.createInterface
asyncIterator
What steps will reproduce the bug?
if you perform something like
https://github.com/nodejs/node/blob/2a7432dadec08bbe7063d84f1aa4a6396807305c/test/parallel/test-readline-async-iterators.js
If you add some kind of await xxx() between creating the interface and iterating, the iterator will miss lines. In my case I input 100k lines from a file, then output those same lines to a new file. several thousand lines will go missing.
How often does it reproduce? Is there a required condition?
100%
Need to add some await async between creating the interface and using for await
What is the expected behavior?
not to miss iterations
What do you see instead?
Additional information
The text was updated successfully, but these errors were encountered: