Skip to content
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

Gunicorn dependent on TTY for SIGINT handling #2444

Closed
chadwhitely opened this issue Oct 29, 2020 · 2 comments
Closed

Gunicorn dependent on TTY for SIGINT handling #2444

chadwhitely opened this issue Oct 29, 2020 · 2 comments

Comments

@chadwhitely
Copy link

It appears that the gunicorn signal handler for sigint is somewhat reliant on a TTY being utilized.

Note for this case: Notice how it waits the GRACEFUL_TIMEOUT duration (which FastAPI sets to 120), despite being a SIGINT.
No TTY, closing with ctrl-c -> SIGINT: 

(general) [vagrant@localhost scrubbed-repo-name]$ docker run tiangolo/uvicorn-gunicorn-fastapi:python3.8
Checking for script in /app/prestart.sh
Running script /app/prestart.sh
Running inside /app/prestart.sh, you could add migrations to this file, e.g.:#! /usr/bin/env bash
# Let the DB start
sleep 10;
# Run migrations
alembic upgrade head[2020-10-29 19:18:54 +0000] [1] [INFO] Starting gunicorn 20.0.4
[2020-10-29 19:18:54 +0000] [1] [INFO] Listening at: http://0.0.0.0:80 (1)
[2020-10-29 19:18:54 +0000] [1] [INFO] Using worker: uvicorn.workers.UvicornWorker
[2020-10-29 19:18:54 +0000] [7] [INFO] Booting worker with pid: 7
[2020-10-29 19:18:55 +0000] [8] [INFO] Booting worker with pid: 8
[2020-10-29 19:18:55 +0000] [8] [INFO] Started server process [8]
[2020-10-29 19:18:55 +0000] [7] [INFO] Started server process [7]
[2020-10-29 19:18:55 +0000] [7] [INFO] Waiting for application startup.
[2020-10-29 19:18:55 +0000] [8] [INFO] Waiting for application startup.
[2020-10-29 19:18:55 +0000] [7] [INFO] Application startup complete.
[2020-10-29 19:18:55 +0000] [8] [INFO] Application startup complete.
^C[2020-10-29 19:18:56 +0000] [1] [INFO] Handling signal: int
[2020-10-29 19:20:56 +0000] [1] [INFO] Shutting down: Master
{"loglevel": "info", "workers": 2, "bind": "0.0.0.0:80", "graceful_timeout": 120, "timeout": 120, "keepalive": 5, "errorlog": "-", "accesslog": "-", "workers_per_core": 1.0, "use_max_workers": null, "host": "0.0.0.0", "port": "80"}

 

Note for this case: Expected behavior
With TTY, closing with ctrl-c -> SIGINT:

(general) [vagrant@localhost scrubbed-repo-name]$ docker run -ti tiangolo/uvicorn-gunicorn-fastapi:python3.8
Checking for script in /app/prestart.sh
Running script /app/prestart.sh
Running inside /app/prestart.sh, you could add migrations to this file, e.g.:#! /usr/bin/env bash
# Let the DB start
sleep 10;
# Run migrations
alembic upgrade head{"loglevel": "info", "workers": 2, "bind": "0.0.0.0:80", "graceful_timeout": 120, "timeout": 120, "keepalive": 5, "errorlog": "-", "accesslog": "-", "workers_per_core": 1.0, "use_max_workers": null, "host": "0.0.0.0", "port": "80"}
[2020-10-29 19:18:31 +0000] [1] [INFO] Starting gunicorn 20.0.4
[2020-10-29 19:18:31 +0000] [1] [INFO] Listening at: http://0.0.0.0:80 (1)
[2020-10-29 19:18:31 +0000] [1] [INFO] Using worker: uvicorn.workers.UvicornWorker
[2020-10-29 19:18:31 +0000] [7] [INFO] Booting worker with pid: 7
[2020-10-29 19:18:31 +0000] [8] [INFO] Booting worker with pid: 8
[2020-10-29 19:18:31 +0000] [7] [INFO] Started server process [7]
[2020-10-29 19:18:31 +0000] [8] [INFO] Started server process [8]
[2020-10-29 19:18:31 +0000] [7] [INFO] Waiting for application startup.
[2020-10-29 19:18:31 +0000] [8] [INFO] Waiting for application startup.
[2020-10-29 19:18:31 +0000] [7] [INFO] Application startup complete.
[2020-10-29 19:18:31 +0000] [8] [INFO] Application startup complete.
^C[2020-10-29 19:18:33 +0000] [1] [INFO] Handling signal: int
[2020-10-29 19:18:33 +0000] [7] [INFO] Shutting down
[2020-10-29 19:18:33 +0000] [7] [INFO] Error while closing socket [Errno 9] Bad file descriptor
[2020-10-29 19:18:33 +0000] [8] [INFO] Shutting down
[2020-10-29 19:18:33 +0000] [8] [INFO] Error while closing socket [Errno 9] Bad file descriptor
[2020-10-29 19:18:33 +0000] [7] [INFO] Waiting for application shutdown.
[2020-10-29 19:18:33 +0000] [7] [INFO] Application shutdown complete.
[2020-10-29 19:18:33 +0000] [7] [INFO] Finished server process [7]
[2020-10-29 19:18:33 +0000] [7] [INFO] Worker exiting (pid: 7)
[2020-10-29 19:18:33 +0000] [8] [INFO] Waiting for application shutdown.
[2020-10-29 19:18:33 +0000] [8] [INFO] Application shutdown complete.
[2020-10-29 19:18:33 +0000] [8] [INFO] Finished server process [8]
[2020-10-29 19:18:33 +0000] [8] [INFO] Worker exiting (pid: 8)
[2020-10-29 19:18:33 +0000] [1] [INFO] Shutting down: Master

 

Note for this case: Expected behavior
To show that this is only for SIGINT, here is a case where we use no TTY, but instead send {{docker stop}} -> SIGTERM:

(general) [vagrant@localhost scrubbed-repo-name]$ docker run tiangolo/uvicorn-gunicorn-fastapi:python3.8
Checking for script in /app/prestart.sh
Running script /app/prestart.sh
Running inside /app/prestart.sh, you could add migrations to this file, e.g.:#! /usr/bin/env bash
# Let the DB start
sleep 10;
# Run migrations
alembic upgrade head[2020-10-29 19:22:39 +0000] [1] [INFO] Starting gunicorn 20.0.4
[2020-10-29 19:22:39 +0000] [1] [INFO] Listening at: http://0.0.0.0:80 (1)
[2020-10-29 19:22:39 +0000] [1] [INFO] Using worker: uvicorn.workers.UvicornWorker
[2020-10-29 19:22:39 +0000] [7] [INFO] Booting worker with pid: 7
[2020-10-29 19:22:39 +0000] [8] [INFO] Booting worker with pid: 8
[2020-10-29 19:22:40 +0000] [8] [INFO] Started server process [8]
[2020-10-29 19:22:40 +0000] [7] [INFO] Started server process [7]
[2020-10-29 19:22:40 +0000] [8] [INFO] Waiting for application startup.
[2020-10-29 19:22:40 +0000] [7] [INFO] Waiting for application startup.
[2020-10-29 19:22:40 +0000] [8] [INFO] Application startup complete.
[2020-10-29 19:22:40 +0000] [7] [INFO] Application startup complete.
[2020-10-29 19:22:45 +0000] [1] [INFO] Handling signal: term
[2020-10-29 19:22:46 +0000] [8] [INFO] Shutting down
[2020-10-29 19:22:46 +0000] [8] [INFO] Error while closing socket [Errno 9] Bad file descriptor
[2020-10-29 19:22:46 +0000] [7] [INFO] Shutting down
[2020-10-29 19:22:46 +0000] [7] [INFO] Error while closing socket [Errno 9] Bad file descriptor
[2020-10-29 19:22:46 +0000] [8] [INFO] Waiting for application shutdown.
[2020-10-29 19:22:46 +0000] [8] [INFO] Application shutdown complete.
[2020-10-29 19:22:46 +0000] [8] [INFO] Finished server process [8]
{"loglevel": "info", "workers": 2, "bind": "0.0.0.0:80", "graceful_timeout": 120, "timeout": 120, "keepalive": 5, "errorlog": "-", "accesslog": "-", "workers_per_core": 1.0, "use_max_workers": null, "host": "0.0.0.0", "port": "80"}
[2020-10-29 19:22:46 +0000] [8] [INFO] Worker exiting (pid: 8)
[2020-10-29 19:22:46 +0000] [7] [INFO] Waiting for application shutdown.
[2020-10-29 19:22:46 +0000] [7] [INFO] Application shutdown complete.
[2020-10-29 19:22:46 +0000] [7] [INFO] Finished server process [7]
[2020-10-29 19:22:46 +0000] [7] [INFO] Worker exiting (pid: 7)
{"loglevel": "info", "workers": 2, "bind": "0.0.0.0:80", "graceful_timeout": 120, "timeout": 120, "keepalive": 5, "errorlog": "-", "accesslog": "-", "workers_per_core": 1.0, "use_max_workers": null, "host": "0.0.0.0", "port": "80"}
[2020-10-29 19:22:46 +0000] [1] [INFO] Shutting down: Master
{"loglevel": "info", "workers": 2, "bind": "0.0.0.0:80", "graceful_timeout": 120, "timeout": 120, "keepalive": 5, "errorlog": "-", "accesslog": "-", "workers_per_core": 1.0, "use_max_workers": null, "host": "0.0.0.0", "port": "80"}
@benoitc
Copy link
Owner

benoitc commented Aug 6, 2024

no activity since awhile. closing feel free to create a new ticket if needed.

note: not sure what was suggested there. If the author can clarify that would be helpful.

@benoitc benoitc closed this as completed Aug 6, 2024
@Jenjen1324
Copy link

Jenjen1324 commented Aug 7, 2024

I figured out this only happens with the uvicorn worker. There seem to have been signal handling issues in the past, though they "should" be fixed already...

Uvicorn also hasn't been updated in a while in that docker image, maybe updating that would fix it? Haven't got time right now to test that.

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

No branches or pull requests

3 participants