-
-
Notifications
You must be signed in to change notification settings - Fork 757
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
[BUG] Received duplicated signal from Gunicorn #1116
Comments
this issue is affecting us as well. Is there a fix that will be done by uvicorn ? |
I'm still waiting for a reply on benoitc/gunicorn#2604. Do you have any suggestion? We could add a handler for |
@Kludex gunicorn is maintaining parity with uwsgi. Both kill off workers + shutdown when SIGINT or SIGQUIT is received. https://uwsgi-docs.readthedocs.io/en/latest/Management.html . in fact in uwsgi 2.1, SIGTERM also shuts down uwsgi. ( https://uwsgi-docs.readthedocs.io/en/latest/ThingsToKnow.html#things-to-know-best-practices-and-issues-read-it) i think (speculating) that the way the internal code is written in both uwsgi and gunicorn is to kill everything in case of these three signals ( https://github.com/unbit/uwsgi/blob/d58a832c81c2c96ae0f6e72614e1cc47f4b5d332/core/emperor.c#L2000-L2002) so ultimately i think that uvicorn will need to honor the gunicorn signal behavior (when running as a worker) and not interpret signals directly. |
Is there any workaround for this problem? This issue block our project deployment timeline. |
Experiencing the same issue with gunicorn and uvicorn workers on GCP cloudrun platform. |
Here is a workaround I am using (is not battle-tested much yet though): @app.on_event("shutdown")
async def shutdown():
await database.disconnect()
if "gunicorn" in os.environ.get("SERVER_SOFTWARE", ""):
loop = asyncio.get_event_loop()
loop.add_signal_handler(signal.SIGQUIT, lambda _: asyncio.create_task(shutdown())) |
Any news about it? |
PR is welcome to modify the |
Yes. 🙏 |
@Kludex I've tested that PR, it works fine, i.e. the shutdown event is triggered, but shouldn't we use the server's Adding SIGQUIT as a handled signal in server just works fine as well, what do you think? server.py
EDIT: #1424 is triggering the shutdown event just fine for SIGINT and shutting down the application, but if we send a SIGQUIT it doesn't handle it. I've created a PR #1709, that does both. |
On my side, I'm not willing to change uvicorn for this, only the |
It will be available on Uvicorn |
Checklist
master
.Describe the bug
Currently, when we send
SIGINT
to thegunicorn
process that is running withuvicorn
workers, theSIGINT
is not propagated to the workers. On its turn, aSIGQUIT
is sent to them. By the time of this issue, the reason for that decision is unclear, but you can follow this gunicorn issue to understand more.The mentioned behavior has an effect on
uvicorn
, that I'm unsure how we should act. The effect is that when runninggunicorn
withuvicorn
workers, theshutdown
event doesn't happen. Which, in theory, is fine. AsSIGINT
andSIGQUIT
, should be terminating the worker immediately, but that is not what is in place for standaloneuvicorn
i.e.SIGNIT
triggers the shutdown event.Well, all of what I mentioned above should actually be a separated issue, but I was not able to solve it without workarounds, that I'm unsure if we want them. The reason for that is the
uvicorn
worker receiving two signals when we sendSIGINT
to thegunicorn
process, one isSIGINT
, which is sent directly to theuvicorn
worker and the other is theSIGQUIT
which is sent by thegunicorn
process.As you see, even if we fix
SIGQUIT
by sendingSIGINT
, the issue is not solved i.e.uvicorn
will receive doubleSIGINT
, and we will force exit (viaforce_exit
attribute).To reproduce
Just create any ASGI app, with a shutdown event:
Then run
gunicorn
withuvicorn
workers:Feel free to press
CTRL + C
and you'll see this log:As you see, the message on the shutdown event doesn't appear.
Expected behavior
If we want to have consistency with the standalone
uvicorn
, which I'm really unsure (as it doesn't feel right to wait the process to finish gracefully withSIGINT
), then we should match this behavior andgunicorn
withuvicorn
workers should trigger the shutdown event as well.In case we decide that the shutdown event should actually not be triggered by standalone
uvicorn
, then the issue here is no more an issue, and we should stop handling theSIGINT
on theserver.py
. I believe this is unlikely to happen, because of practicality when developing.Actual behavior
The shutdown event is not triggered running
gunicorn
withuvicorn
workers whenSIGINT
is sent.Environment
Additional context
More context can be found on Gitter. Here are some messages, but you can follow the discussion there:
https://gitter.im/encode/community?at=60e3592b457e19611a37a5d6
https://gitter.im/encode/community?at=60e35dd8f862a72a30eeb8dc
https://gitter.im/encode/community?at=60e5966e24f0ae2a244a5e0d
\cc @tomchristie @florimondmanca
The text was updated successfully, but these errors were encountered: