Repository navigation
devpts: do not hang up master before its replica is opened - #17244
Merged
Merged
Conversation
milantracy
previously requested changes
Nov 23, 2026
ayushr2
previously approved these changes
Nov 23, 2026
Contributor
|
can you rebase and push again |
ayushr2
reviewed
Nov 23, 2026
gVisor treats a PTY master as hung up whenever it has no open replica file descriptors, including before any replica has been opened. In that state, poll() on the master reports POLLHUP and read() fails with EIO. A program that opens a PTY, forks a child that opens the replica, and reads the master at once sees a hang up if the read runs before the child opens the replica. On Linux, the master is only hung up once a replica has been opened and then closed again. Before the first open, poll() on the master does not report POLLHUP, and read() blocks or, if the master is nonblocking, fails with EAGAIN. Track whether a replica was ever opened, and only treat the master as hung up if one was and none are left. Local Nix builds fail at random under runsc because of this (NixOS/nix#15181). Nix reads the builder's startup line from a PTY master while the forked builder opens the replica. When the read runs first, Nix fails with "unexpected EOF reading a line". Tools like expect and script that poll the master of a new session have the same race. Fixes gvisor#13738 Signed-off-by: faukah <[email protected]> Change-Id: If185581843f5f6b7b2a510f6f54a4e4a6a6a6964
ayushr2
approved these changes
Nov 23, 2026
milantracy
approved these changes
Nov 24, 2026
milantracy
enabled auto-merge (squash)
November 24, 2026 05:06
milantracy
disabled auto-merge
November 24, 2026 05:06
milantracy
enabled auto-merge (squash)
November 24, 2026 05:07
EtiennePerot
pushed a commit
that referenced
this pull request
Nov 26, 2026
gVisor treats a PTY master as hung up whenever it has no open replica file descriptors, including before any replica has been opened. In that state, poll() on the master reports POLLHUP and read() fails with EIO. A program that opens a PTY, forks a child that opens the replica, and reads the master at once sees a hang up if the read runs before the child opens the replica. Local Nix builds fail at random under runsc because of this ([NixOS/nix#15181](NixOS/nix#15181)). Nix reads the builder's startup line from a PTY master while the forked builder opens the replica. When the read runs first, Nix fails with "unexpected EOF reading a line". A minimal reproduction example for this: ```python import os, fcntl, struct, select m = os.open("/dev/ptmx", os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK) fcntl.ioctl(m, 0x40045431, struct.pack("i", 0)) # TIOCSPTLCK p = select.poll(); p.register(m, select.POLLIN | select.POLLOUT) print("revents:", p.poll(0)) try: os.read(m, 1) except OSError as e: print("read:", e.strerror) ``` ``` poll read Linux 7.3.1 POLLOUT EAGAIN runsc, without fix POLLOUT|POLLHUP EIO runsc, with fix POLLOUT EAGAIN ``` There's been some related work on this as well: PR #14505 closed #13738, but it fixed a different devpts bug (ESPIPE on positional I/O); this change _actually_ fixes the bug the issue reports. The POLLHUP for a master without replicas came from the fix for #9951 and #9333, which still work because they close a replica that was opened. Fixes #13738. (I think it makes sense to re-open that one, since it's still valid, and have it closed by this pr?) Signed-off-by: faukah <[email protected]> (cherry picked from commit 5cc6d03)
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.
hello 👍
gVisor treats a PTY master as hung up whenever it has no open replica file descriptors, including before any replica has been opened. In that state, poll() on the master reports POLLHUP and read() fails with EIO. A program that opens a PTY, forks a child that opens the replica, and reads the master at once sees a hang up if the read runs before the child opens the replica.
Local Nix builds fail at random under runsc because of this (NixOS/nix#15181). Nix reads the builder's startup line from a PTY master while the forked builder opens the replica. When the read runs first, Nix fails with
"unexpected EOF reading a line".
A minimal reproduction example for this:
There's been some related work on this as well: PR #14505 closed #13738, but it fixed a different devpts bug (ESPIPE on positional I/O); this change actually fixes the bug the issue reports.
The POLLHUP for a master without replicas came from the fix for #9951 and #9333, which still work because they close a replica that was opened.
Fixes #13738.
(I think it makes sense to re-open that one, since it's still valid, and have it closed by this pr?)