libutil: treat EIO as EOF in readLine#15323
Merged
Ericson2314 merged 1 commit intoNixOS:masterfrom Feb 23, 2026
Merged
Conversation
17a4c8a to
f4c0aa0
Compare
Reading from a pty master returns `EIO` once the slave side closes, however, `readLine` lets it propagate as an uncaught `SysError`, which causes spurious build failures in gvisor and similar sandboxed environments where pty teardown races differently. This commit catches `EIO` inside the read lambda and maps it to a zero-length read, reusing the existing EOF path.
f4c0aa0 to
994137d
Compare
Ericson2314
approved these changes
Feb 23, 2026
xokdvium
reviewed
Feb 23, 2026
Comment on lines
+80
to
+89
| try { | ||
| return read(fd, {reinterpret_cast<std::byte *>(&ch), 1}); | ||
| } catch (SystemError & e) { | ||
| // On pty masters, EIO signals that the slave side closed, | ||
| // which is semantically EOF. Map it to a zero-length read | ||
| // so the existing EOF path handles it. | ||
| if (e.is(std::errc::io_error)) | ||
| return 0; | ||
| throw; | ||
| } |
Contributor
There was a problem hiding this comment.
Shouldn't we apply the same treatment to FdSource::readLine/readUnbuffered under a certain flag maybe? I don't think we want to keep the one-byte-at-a-time reading function for too long anyway.
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.
Motivation
Reading from a pty master returns
EIOonce the slave side closes, however,readLinelets it propagate as an uncaughtSysError, which causes spurious build failures in gvisor and similar sandboxed environments where pty teardown races differently. This commit catchesEIOinside the read lambda and maps it to a zero-length read, reusing the existing EOF path.Context
When pty support was first added in #2878, EIO was handled at the call site, but a later refactor moved reading to the generic
readLinewhich didn't carry the handling over, though muxable-pipe.cc still has it.Note that the test is skipped on macOS, because macOS returns EOF with 0 immediately and discards all buffered data (ref).
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.