-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(posix): use fcntl to check if a fd is nonblocking (#10080)
The FileReader is responsible for deciding what sort of file descriptor has been passed to it. On MacOS, when stdin is provided to it the FileReader assumes that it is nonblocking even if the descriptor is not as it passes the pollable and not a tty check, this then results in hangs as the reader expects `EAGAIN`. To fix this we now check the file descriptor to see if it is nonblocking rather than using assumptions.
- Loading branch information
1 parent
fbe2fe0
commit debc9bf
Showing
3 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { test, expect } from "bun:test"; | ||
import { bunEnv, bunExe, isPosix } from "harness"; | ||
import { tmpdir } from "os"; | ||
import { join } from "path"; | ||
|
||
test.if(isPosix)("10080 - ensure blocking stdio is treated as such in FileReader", async () => { | ||
const expected = "foobar\n"; | ||
const filename = join(tmpdir(), "bun.test.stream." + Date.now() + ".js"); | ||
const contents = "for await (const line of console) {console.log(`foo${line}`)}" | ||
await Bun.write(filename, contents); | ||
const shellCommand = `exec &> >(${bunExe()} ${filename}); echo "bar"; while read -r line; do echo $line; done`; | ||
|
||
const proc = Bun.spawn(["bash", "-c", shellCommand], { | ||
stdin: "inherit", | ||
stdout: "pipe", | ||
stderr: "inherit", | ||
env: bunEnv, | ||
}); | ||
const { value }= await proc.stdout.getReader().read(); | ||
const output = new TextDecoder().decode(value); | ||
if (output !== expected) { | ||
expect(output).toEqual(expected); | ||
throw new Error("Output didn't match!\n"); | ||
} | ||
|
||
proc.kill(9); | ||
await proc.exited; | ||
expect(proc.killed).toBeTrue(); | ||
}, 1000); |