Repository navigation
Bun.file().stream(): poll a dup of a stdio pipe, socket or terminal #46807
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -240,6 +240,18 @@ impl Lazy { | |
| } | ||
| } | ||
|
|
||
| // Off Linux a pipe reader that wakes after another registration took the bytes blocks in `read`. | ||
| #[cfg(unix)] | ||
| let two_can_poll = cfg!(any(target_os = "linux", target_os = "android")) | ||
| || this.file_type == FileType::Socket; | ||
| // An event loop keeps one registration per fd number, so a reader that polls a stdio fd takes a dup. | ||
| #[cfg(unix)] | ||
| let fd = if two_can_poll && this.pollable && fd.stdio_tag().is_some() { | ||
| sys::dup_at_least(fd, 3).unwrap_or(fd) | ||
|
Comment on lines
+249
to
+250
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Programs with a live Why this was flaggedA program registers Verification: The PR description's "Decision needed" section and its table row record exactly this outcome, and the new test at test/js/web/streams/streams.test.js:3010-3023 pins only that the concatenated text of both readers equals the input ("each byte goes to one"), not that the earlier listener keeps receiving.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is correct, and it is the question at the top of the description. I measured the same result. On a release build of this branch the later stream takes all 35 bytes from a listening The costs of each answer, as far as I measured or can read from the code:
I leave this thread open for a maintainer to choose. |
||
| } else { | ||
| fd | ||
| }; | ||
|
|
||
| this.fd = fd; | ||
|
|
||
| Ok(this) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.