pty: Send SIGHUP to foreground process group when master is closed#12855
Open
tanyifeng wants to merge 1 commit intogoogle:masterfrom
Open
pty: Send SIGHUP to foreground process group when master is closed#12855tanyifeng wants to merge 1 commit intogoogle:masterfrom
tanyifeng wants to merge 1 commit intogoogle:masterfrom
Conversation
When the PTY master file descriptor is closed, Linux sends SIGHUP to the foreground process group of the session that has this PTY as its controlling terminal. gVisor was missing this behavior entirely: closing the master end did not send any signal, causing child processes spawned via PTY to remain running indefinitely instead of being notified of the hangup. Fix by adding a TTY.Hangup() method that reuses the existing ReleaseControllingTTY() logic to send SIGHUP/SIGCONT and clear the controlling terminal. Call Hangup() for both masterKTTY and replicaKTTY in masterClose(). Signed-off-by: Tan Yifeng <[email protected]>
Contributor
Author
Reproducer# In a gVisor container — child should be killed when expect exits
docker run --runtime=runsc --rm alpine sh -c '
apk add --no-cache expect procps >/dev/null 2>&1
cat > /tmp/test.exp << "END"
spawn sleep 300
expect timeout
END
expect -f /tmp/test.exp &
PID=$!
sleep 2
SLEEP_PID=$(ps -ef | awk "/sleep 300/ && !/awk|sh -c/ {print \$2}" | head -1)
echo "Sleep PID: $SLEEP_PID"
kill $PID 2>/dev/null
sleep 2
if [ -n "$SLEEP_PID" ] && kill -0 "$SLEEP_PID" 2>/dev/null; then
echo "BUG: sleep process still running after expect exit"
else
echo "OK: sleep process terminated"
fi
'Before fix: |
EtiennePerot
approved these changes
Apr 2, 2026
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.
When the PTY master file descriptor is closed, Linux sends SIGHUP to the foreground process group of the session that has this PTY as its controlling terminal.
gVisor was missing this behavior entirely: closing the master end did not send any signal, causing child processes spawned via PTY to remain running indefinitely instead of being notified of the hangup.
Fix by adding a TTY.Hangup() method that reuses the existing ReleaseControllingTTY() logic to send SIGHUP/SIGCONT and clear the controlling terminal. Call Hangup() for both masterKTTY and replicaKTTY in masterClose().