fix(io): Prevent hang in sliced BunFile stream on large files - #25796
mattermoran wants to merge 2 commits into
Conversation
WalkthroughAdjusts FileReader chunk-read control flow to set closure flags when a max_size is reached and ensures closure checks run after consuming a buffer. Adds two regression tests exercising streamed slices of Bun.file() to reproduce/verify fixes for hanging/freeze scenarios. Changes
Suggested reviewers
Pre-merge checks✅ Passed checks (4 passed)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Disabled knowledge base sources:
📥 CommitsReviewing files that changed from the base of the PR and between 5f093416613ed735d408cb2fe973701ca670f1eb and 05fd100. 📒 Files selected for processing (3)
🧰 Additional context used📓 Path-based instructions (7)src/**/*.zig📄 CodeRabbit inference engine (src/CLAUDE.md)
Files:
**/*.zig📄 CodeRabbit inference engine (CLAUDE.md)
Files:
test/**/*.test.{ts,js,jsx,tsx,mjs,cjs}📄 CodeRabbit inference engine (test/CLAUDE.md)
Files:
test/regression/issue/**/*.test.ts📄 CodeRabbit inference engine (test/CLAUDE.md)
Files:
**/*.test.ts?(x)📄 CodeRabbit inference engine (CLAUDE.md)
Files:
test/regression/issue/*.test.ts📄 CodeRabbit inference engine (CLAUDE.md)
Files:
test/**/*.test.ts?(x)📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🧠 Learnings (20)📓 Common learnings📚 Learning: 2025-10-17T20:50:58.644ZApplied to files:
📚 Learning: 2025-11-24T18:36:59.706ZApplied to files:
📚 Learning: 2025-11-24T18:37:30.259ZApplied to files:
📚 Learning: 2025-12-16T00:21:32.179ZApplied to files:
📚 Learning: 2025-12-16T00:21:32.179ZApplied to files:
📚 Learning: 2025-10-26T01:32:04.844ZApplied to files:
📚 Learning: 2025-11-24T18:37:30.259ZApplied to files:
📚 Learning: 2025-11-24T18:37:30.259ZApplied to files:
📚 Learning: 2025-11-24T18:37:30.259ZApplied to files:
📚 Learning: 2025-12-16T00:21:32.179ZApplied to files:
📚 Learning: 2025-11-24T18:37:30.259ZApplied to files:
📚 Learning: 2025-11-08T04:06:33.198ZApplied to files:
📚 Learning: 2025-11-06T00:58:23.965ZApplied to files:
📚 Learning: 2025-11-24T18:37:30.259ZApplied to files:
📚 Learning: 2025-11-24T18:37:30.259ZApplied to files:
📚 Learning: 2025-12-16T00:21:32.179ZApplied to files:
📚 Learning: 2025-10-19T02:44:46.354ZApplied to files:
📚 Learning: 2025-10-01T22:13:08.081ZApplied to files:
📚 Learning: 2025-10-04T21:17:53.040ZApplied to files:
🧬 Code graph analysis (1)test/regression/issue/21175.test.ts (2)
🔇 Additional comments (4)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
found a similar issue that I will address as well first #21175 |
5f09341 to
05fd100
Compare
|
confirmed this fixes #21175 as well |
|
Closing as stale: this PR predates the Rust rewrite. Every If the underlying change is still wanted, it will need to be redone against the current Rust/C++ tree. Apologies for the churn, and thank you for the contribution. |
Fixes #18192
Fixes #21175
Properly closes the stream when
max_sizeis reached.Previously just checking
buf.len == 0was not enough as that could trigger another read but then it would hit thethis.total_readed >= max_sizeguard and return without closing the stream leading to a hang.Rather than checking
buf.len == 0it's better tothis.total_readed >= max_sizeto check if we already at the end.The first
ifwas also modified to handle edge case with 0 length slice as that would hang as well.