pty: Send SIGHUP to foreground process group when master is closed#12855
Merged
copybara-service[bot] merged 1 commit intogoogle:masterfrom Apr 16, 2026
Merged
Conversation
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
shailend-g
reviewed
Apr 14, 2026
5042b00 to
b773847
Compare
shailend-g
reviewed
Apr 14, 2026
When the PTY master is closed, send SIGHUPto the foreground process group of the session that has the slave as its controlling terminal. This matches Linux's pty_close() -> tty_vhangup(tty->link) behavior (drivers/tty/pty.c). Without this, child processes spawned via PTY (e.g. by expect/telnet) are never notified of the hangup and remain running indefinitely. Signed-off-by: Tan Yifeng <yiftan@tencent.com>
b773847 to
1686126
Compare
shailend-g
approved these changes
Apr 15, 2026
copybara-service Bot
pushed a commit
that referenced
this pull request
Apr 15, 2026
When the PTY master is closed, send SIGHUPto the foreground process group of the session that has the slave as its controlling terminal. This matches Linux's pty_close() -> tty_vhangup(tty->link) behavior (drivers/tty/pty.c). Without this, child processes spawned via PTY (e.g. by expect/telnet) are never notified of the hangup and remain running indefinitely. FUTURE_COPYBARA_INTEGRATE_REVIEW=#12855 from tanyifeng:pty-sighup-on-master-close 1686126 PiperOrigin-RevId: 900302848
copybara-service Bot
pushed a commit
that referenced
this pull request
Apr 15, 2026
When the PTY master is closed, send SIGHUPto the foreground process group of the session that has the slave as its controlling terminal. This matches Linux's pty_close() -> tty_vhangup(tty->link) behavior (drivers/tty/pty.c). Without this, child processes spawned via PTY (e.g. by expect/telnet) are never notified of the hangup and remain running indefinitely. FUTURE_COPYBARA_INTEGRATE_REVIEW=#12855 from tanyifeng:pty-sighup-on-master-close 1686126 PiperOrigin-RevId: 900302848
copybara-service Bot
pushed a commit
that referenced
this pull request
Apr 15, 2026
When the PTY master is closed, send SIGHUPto the foreground process group of the session that has the slave as its controlling terminal. This matches Linux's pty_close() -> tty_vhangup(tty->link) behavior (drivers/tty/pty.c). Without this, child processes spawned via PTY (e.g. by expect/telnet) are never notified of the hangup and remain running indefinitely. FUTURE_COPYBARA_INTEGRATE_REVIEW=#12855 from tanyifeng:pty-sighup-on-master-close 1686126 PiperOrigin-RevId: 900302848
copybara-service Bot
pushed a commit
that referenced
this pull request
Apr 16, 2026
When the PTY master is closed, send SIGHUPto the foreground process group of the session that has the slave as its controlling terminal. This matches Linux's pty_close() -> tty_vhangup(tty->link) behavior (drivers/tty/pty.c). Without this, child processes spawned via PTY (e.g. by expect/telnet) are never notified of the hangup and remain running indefinitely. FUTURE_COPYBARA_INTEGRATE_REVIEW=#12855 from tanyifeng:pty-sighup-on-master-close 1686126 PiperOrigin-RevId: 900302848
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.
pty: Send SIGHUP to foreground process group on master close
When the PTY master is closed, send SIGHUPto the foreground process group of the session that has the slave as its controlling terminal. This matches Linux's pty_close() -> tty_vhangup(tty->link) behavior (drivers/tty/pty.c).
Without this, child processes spawned via PTY (e.g. by expect/telnet) are never notified of the hangup and remain running indefinitely.