-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 doesn't shutdown immediately on receiving SIGTERM #1256
Comments
Do you have open connections when this happens? If so, that is expected. SIGTERM is a graceful shutdown and subject to the At present, at least on the master branch, I observe a worker exiting within 1s of sending SIGTERM to the arbiter, tested on Python 3.5. |
There is no open connection. As shown in the gist, All that the script does is start gunicorn and send a SIGTERM. |
Happens to me with the master branch as well. This is with Python 3.5 on Ubuntu 16.04. Maybe, this happens because of Ubuntu.
|
The same behavior happens with Python 3.5, Gunicorn (master, commit 9d158be), Centos 7.
Python 3.4 does not have this issue.
|
You're right. I do observe this on Python 3. Perhaps I made a mistake earlier when I was testing. |
I also agree with the diagnosis. |
I don't believe this affects any of the async workers or the threaded worker. |
PEP 475 https://www.python.org/dev/peps/pep-0475/#backward-compatibility has some information how this should be addressed.
|
Just tested it and was able to reproduce it. At least for me gunicorn exit is delayed. Removing the After debugging a little, it appears that after receiving the signal, the select is indeed blocking there: I am not sure yet how to solve the issue, I will reread the PEP 475 carefully this morning to see if it can give a solution, thanks for the link! |
in python 3.5 the select is blocking when waiting for it which prevent quick exit on SIGTERM. The problem is described: https://www.python.org/dev/peps/pep-0475/#backward-compatibility This change fix it by listening for signal event on the worker pipe. Once an event is triggered it will forcefully wake up the select and return. fix #1256
The test script run-and-stop-gunicorn.sh behaves identically with Python 3.5 and Python 3.4. The pull request addresses the SIGTERM issue. @benoitc Are there other parts of the gunicorn that break because of PEP 475? |
@suriya not to my knowledge, I tested with other workers and it was fine. |
@suriya so the patch is fixing your issue right? |
@benoitc Yes, absolutely fixing the issue. Thank you. I was just wondering if there would be other places that might need to be fixed since the effects of PEP 475 seem to be pervasive. |
@suriya normally not, but will keep an eye on it :-) |
in python 3.5 the select is blocking when waiting for it which prevent quick exit on SIGTERM. The problem is described: https://www.python.org/dev/peps/pep-0475/#backward-compatibility This change fix it by listening for signal event on the worker pipe. Once an event is triggered it will forcefully wake up the select and return. fix benoitc#1256
For those who arrive here and wonder in what version in gunicorn this was fixed, it's 19.5.0 |
I am seeing a weird behavior where Gunicorn does not shutdown immediately when sent a SIGTERM. I see this with Python 3.5 on Ubuntu 16.04. The following environments (that I have access to) do not exhibit this issue:
Refer to https://gist.github.com/suriya/1d9a11ea9ad33a5b1df0b2ba7ed0cd0e on how to reproduce this issue.
After debugging a while, I found that the Gunicorn arbiter properly signals the child worker. The child workers handle the signal properly as well (on all versions). However, something prevents the loop in
run_for_one
functiongunicorn/gunicorn/workers/sync.py
Line 58 in 9d158be
Could Python 3.5's change in the behavior of
select.select()
https://docs.python.org/3/library/select.html#select.select explain this issue.The text was updated successfully, but these errors were encountered: