Repository navigation
fix(io): File.read and its twins read through fs on Node, where bun:ffi is missing - #1881
Merged
Lorenzobattistela merged 3 commits intoOct 27, 2026
Merged
Conversation
… FFI path readvSync makes the syscall for a 0-byte read, the case the FFI read was added for (Bun's readSync skips it), so the reads need no bun:ffi on Bun either: one fs path, no fallback flag, no second errno source. libuv retries EINTR, so the loop drops its own retry. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
libuv's sync read does not retry an interrupted read, so readvSync can throw EINTR; the loop retries it, as file_read.c does. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Lorenzobattistela
approved these changes
Oct 27, 2026
nicolas-abril
added a commit
to nicolas-abril/bend
that referenced
this pull request
Nov 5, 2026
… park case The JS io_sys bound pread for the old file_read.js, which moved to readvSync in bendlang#1881. ALC's extra row was for the old ALC[1 + arg] indexing; the main thread uses ALC[0] and workers ALC[1..pool_size-1] since bendlang#1269. io_park_add's w->next == w case writes what the next line writes anyway. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
File.read,read_line,read_bytesandread_atend the run on Node, becausefile_read.jsasksio_sys()for libc'sread/pread, and that needsbun:ffi:This is the same kind of bug as #1468, but for reads. When
io_sys()throws, the reads now go throughfs.readvSync, and the errno comes from the thrown error. On Bun nothing changes: the FFI path is the same code. I usedreadvSyncand notreadSyncbecausereadSyncskips the syscall for a 0-byte read, soFile.read(h, 0)on a write-only handle would answer""instead of EBADF. A failedrequire("bun:ffi")costs about 10 µs on Node (readSynccosts about 0.4 µs), so the first failure is cached. Without the cache, 200k small reads took 3.2 s on Node. With it they take about 0.3 s.tests/io/file_read_no_ffi.{bend,js}followsfile_size_no_ffi: the twin makesio_sys()throw, the test reads"hello\nbye"through all four effects, then reads 64 bytes and 0 bytes from an append-only handle (bothfail 9). On main it printsError: no ffi table on this host(exit 1). With the fix it passes on interp and JS. The same.bendwithout the twin also prints the expected lines under real Node 25.9.file_size_no_ffiandtcp_connect_no_ffi, pass on interp, JS and C: 57/57. I ran them locally, not on the minis.gates/repo.ts: 54/54.File.read: p50 going from 22.2 to 21.8 ms, p95 from 25.4 to 22.9 ms, peak RSS 122.8 MB on bothFile.read(f, 16): p50 going from 201.9 to 201.0 ms, p95 from 203.7 to 205.1 ms, CPU 0.29 s and RSS 51.2 MB on bothThe TCP/UDP effects still need
bun:ffion Node, as on main. I left them alone.