Skip to content

Fix pipe read/write using wrong offset in io_uring backend - #299

Merged
lalinsky merged 1 commit into
mainfrom
fix-pipe-write-offset
Feb 7, 2026
Merged

lalinsky merged 1 commit into
mainfrom
fix-pipe-write-offset

Conversation

@lalinsky

@lalinsky lalinsky commented Feb 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • PipeRead and PipeWrite in the io_uring backend used offset 0 for prep_readv/prep_writev, which translates to preadv2/pwritev2 at file position 0
  • This caused repeated writes to overwrite from the beginning when a pipe fd was actually a regular file (e.g. stdout redirected to a file with > output.txt)
  • Changed to offset -1 (@bitCast(@as(i64, -1))) which tells io_uring to use the current file position, matching regular readv/writev behavior

@coderabbitai

coderabbitai Bot commented Feb 7, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Two IO_uring pipe operation submissions were modified: the offset parameter in prep_readv and prep_writev calls changed from 0 to bitCast(-1, i64). This alters the offset value passed to the kernel for pipe read/write operations without modifying surrounding logic or control flow.

Changes

Cohort / File(s) Summary
Pipe offset parameter
src/ev/backends/io_uring.zig
Modified offset parameter from 0 to @bitCast(-1, i64) in two pipe I/O SQE submissions for prep_readv and prep_writev operations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

📨 A pipe's offset shifts from zero to -1,
Kernel-side tweaks for I/O that's begun,
Two lines dance in the uring sky,
Letting pipes read and write on high. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing pipe read/write offset handling in the io_uring backend.
Description check ✅ Passed The description clearly explains the problem (offset 0 causing overwrites), the symptom (file writes starting from position 0), and the solution (using offset -1 for current position).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-pipe-write-offset

No actionable comments were generated in the recent review. 🎉


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@lalinsky
lalinsky force-pushed the fix-pipe-write-offset branch from 1716ece to 62a73c6 Compare February 7, 2026 19:40
PipeRead and PipeWrite used offset 0 in prep_readv/prep_writev, which
in io_uring translates to preadv2/pwritev2 at file position 0. This
caused repeated writes to overwrite from the beginning when stdout was
redirected to a file. Use offset -1 to indicate "use current file
position", matching the behavior of regular readv/writev syscalls.
@lalinsky
lalinsky force-pushed the fix-pipe-write-offset branch from 62a73c6 to a3a7257 Compare February 7, 2026 20:10
@lalinsky
lalinsky merged commit 682fe89 into main Feb 7, 2026
14 checks passed
@lalinsky
lalinsky deleted the fix-pipe-write-offset branch February 7, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant