Skip to content

io_uring, kqueue: return error.InputOutput for EIO on read - #263

Open
cw228 wants to merge 1 commit into
mitchellh:mainfrom
cw228:read-eio
Open

cw228 wants to merge 1 commit into
mitchellh:mainfrom
cw228:read-eio

Conversation

@cw228

@cw228 cw228 commented Nov 26, 2026

Copy link
Copy Markdown

Problem

Reading a PTY master after the slave side has closed (e.g. the shell exited) fails with EIO on Linux. The io_uring backend's readResult has no case for it, so it goes through posix.unexpectedErrno (which prints a stack trace in debug builds) and the callback gets error.Unexpected. On kqueue, mapReadError also folds error.InputOutput from posix.read into error.Unexpected.

The epoll backend already reports this as error.InputOutput, because its ReadError includes posix.ReadError. So a caller that wants to treat EIO as a hangup has to accept error.Unexpected on io_uring/kqueue, which also hides real unexpected errors.

Fix

  • io_uring: map .IO to error.InputOutput in readResult, and add InputOutput to ReadError.
  • kqueue: add InputOutput to ReadError and pass it through in mapReadError.

Test

io_uring: pty read after hangup is InputOutput opens /dev/ptmx, unlocks it, opens and closes the slave, then reads the master through the loop. It skips if /dev/ptmx can't be opened. Without the fix it fails with unexpected 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 cancellation fails with NotFound on main too, so it's unrelated to this change.)

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>
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