Repository navigation
Conversation
Reading a PTY master after the slave side has closed fails with EIO on Linux. The io_uring backend had no case for it, so it went through unexpectedErrno (a stack trace in debug builds) and came back as error.Unexpected. kqueue's mapReadError folded it into Unexpected too. The epoll backend already returns error.InputOutput through posix.ReadError, so callers can now handle a hangup the same way on every backend. Adds a test that opens a PTY pair, closes the slave and reads the master on io_uring. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
Reading a PTY master after the slave side has closed (e.g. the shell exited) fails with
EIOon Linux. The io_uring backend'sreadResulthas no case for it, so it goes throughposix.unexpectedErrno(which prints a stack trace in debug builds) and the callback getserror.Unexpected. On kqueue,mapReadErroralso foldserror.InputOutputfromposix.readintoerror.Unexpected.The epoll backend already reports this as
error.InputOutput, because itsReadErrorincludesposix.ReadError. So a caller that wants to treat EIO as a hangup has to accepterror.Unexpectedon io_uring/kqueue, which also hides real unexpected errors.Fix
.IOtoerror.InputOutputinreadResult, and addInputOutputtoReadError.InputOutputtoReadErrorand pass it through inmapReadError.Test
io_uring: pty read after hangup is InputOutputopens/dev/ptmx, unlocks it, opens and closes the slave, then reads the master through the loop. It skips if/dev/ptmxcan't be opened. Without the fix it fails withunexpected errno: 5; with it it passes. Run on aarch64 Linux 5.15 (Docker, cross-compiled from macOS with Zig 0.17.0). All tests pass on macOS (aarch64). I didn't add a kqueue test: on macOS a PTY master returns EOF instead of EIO after hangup.(On that 5.15 kernel,
io_uring: socket read cancellationfails withNotFoundonmaintoo, so it's unrelated to this change.)