-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pty.spawn'd sh shell doesn't exit via 'exit' or CTRL-D (^D) #9333
Comments
I think the failure to exit has something to do with an ignored SIGCHILD. I can see this in the debug logs:
and if I modify the Python program to handle SIGCHILD I can get the shell to exit using the import os
import pty
import signal
def handler(signum, frame):
print('Signal handler called with signal', signum)
os.waitpid(-1, 0)
raise KeyboardInterrupt()
# gVisor is ignoring the SIGCHILD 'Discarding ignored signal 17'
signal.signal(signal.SIGCHLD, handler)
try:
pty.spawn("sh")
except KeyboardInterrupt:
print("child exited") $ docker run -it --runtime=runsc python:3.9.9-slim-bullseye python3 -c "$(cat minimal_exit.py)"
# exit
Signal handler called with signal 17
child exited
$ |
The issue with CTRL-D handling appears to be that |
Thanks for digging into the issue! Do you have a ready patch for a fix? I am happy to review and merge the PR |
I've opened #9336 which attempts to address the CTRL-D issue, but haven't yet looked at the signal issue. |
A friendly reminder that this issue had no activity for 120 days. |
I can reproduce this with import pty
pty.spawn(["python3", "-c", "print('hello')"]) As well as import os
from pty import _copy
pid, fd = os.forkpty()
if pid == 0:
try:
os.setsid()
except OSError:
# os.forkpty() already set us session leader
pass
os.execlp("python3", "python3", "-c", "print('hi')")
_copy(fd)
print("I will never run on gvisor")
os.close(fd)
print(os.waitpid(pid, 0)[1]) I think the root cause may be that |
Whoops looks like this one fell through the cracks. Thanks for deduping this with the other issue @thecodingwizard. #9979 should fix this. |
Description
On a Linux host, the following terminal program can be exited by using the
exit
program or using the Ctrl + d control signal:python3 -c "import pty; pty.spawn('sh')"
In Docker when using the
runc
runtime, the same is possible:docker run -it python:3.9.9-slim-bullseye python3 -c "import pty; pty.spawn('sh')"
But in gVisor:
docker run -it --runtime=runsc python:3.9.9-slim-bullseye python3 -c "import pty; pty.spawn('sh')"
On issuing
exit
it hangs:and Ctrl + d does nothing.
Steps to reproduce
1. Install gvisor
2. Setup gvisor config in Docker config
/etc/docker/daemon.json
Run
sudo systemctl reload docker
docker run -it --runtime=runsc python:3.9.9-slim-bullseye python3 -c "import pty; pty.spawn('sh')"
Then try to exit the shell.
Kill the container with
docker kill $(docker ps | grep bulls | awk '{print $1;}')
runsc version
docker version (if using docker)
Client: Docker Engine - Community Version: 23.0.1 API version: 1.42 Go version: go1.19.5 Git commit: a5ee5b1 Built: Thu Feb 9 19:46:56 2023 OS/Arch: linux/amd64 Context: default Server: Docker Engine - Community Engine: Version: 23.0.1 API version: 1.42 (minimum version 1.12) Go version: go1.19.5 Git commit: bc3805a Built: Thu Feb 9 19:46:56 2023 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.18 GitCommit: 2456e983eb9e37e47538f59ea18f2043c9a73640 runc: Version: 1.1.4 GitCommit: v1.1.4-0-g5fd4c4d docker-init: Version: 0.19.0 GitCommit: de40ad0
uname
Linux ip-172-31-70-51 5.15.0-1039-aws #44~20.04.1-Ubuntu SMP Thu Jun 22 12:21:12 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
kubectl (if using Kubernetes)
No response
repo state (if built from source)
No response
runsc debug logs (if available)
runsc.log.20230901-231408.518416.delete.txt
runsc.log.20230901-231408.550463.delete.txt
runsc.log.20230901-231329.146610.create.txt
runsc.log.20230901-231329.180715.gofer.txt
runsc.log.20230901-231329.182201.boot.txt
runsc.log.20230901-231329.462248.start.txt
runsc.log.20230901-231408.386346.kill.txt
The text was updated successfully, but these errors were encountered: