You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 23, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 23, 2023. It is now read-only.
When using gunicorn, at least, and a worker times out, gunicorn sends a SIGABRT signal to the worker process. This manifests itself as a SystemExit exception that gets raised in the worker.
When this happens in Django, Django completely ignores SystemExit and lets it re-raise so the process can exit, without ever calling the got_request_exception signal, so in our case, we never see the exception and nobody knows that anything happened since it happily exited without a fuss.
My proposal would be to explicitly catch SystemExit, log, then reraise.
imo this seems like a reasonable thing to do within a middleware. If something is trying to shut down the process while in the middle of the request, probably worth logging.
In gunicorn, this wouldn't log for a normal shutdown, since that sends a SIGTERM instead of SIGABRT.
Would need to be tested against other wsgi runners, specifically uwsgi.
This timeout is specifically when gunicorn kills the worker because it was taking too long to respond. Maybe a busy loop or something like that. So this goes unnoticed.
If the client disconnects, it should be an IOError or something akin to that. I'd have to investigate exactly what happens in that case a bit more. But it's unlikely that it's a SystemExit since that's telling the process to die.
The problem is that "SystemExit" is not a generic error. It'd be akin to us logging an error whenever you called sys.exit(1), which doesnt make much sense. We have the syshook handlers which capture things that get bubbled up (and raise SystemExit should), so I'm not sure what case this is specifically trying to cater towards.
It'd be akin to us logging an error whenever you called sys.exit(1), which doesnt make much sense
I think this is different since it's happening within the wsgi middleware, so the sys.exit() would have to have been called at some point within the request. Which... imo probably worth logging, but could be wrong. Not sure when someone would ever legitimately do that.
We have the syshook handlers which capture things that get bubbled up (and raise SystemExit should)
I'll investigate this and see if that's triggered. I forgot about that.
so I'm not sure what case this is specifically trying to cater towards.
The specific case is a view in your app that is timing out and the process is getting killed without you knowing about it since nothing was logged. This would log it and log where it was killed from.
For example, the stacktrace looks like this:
[2015-10-27 00:38:40 -0700] [13684] [CRITICAL] WORKER TIMEOUT (pid:13687)
Traceback (most recent call last):
File ".../timeout.py", line 5, in application
sleep(5)
File ".../gunicorn/workers/base.py", line 159, in handle_abort
sys.exit(1)
SystemExit: 1
We don't ignore it specifically, but it's not caught by Exception since it's stemming from BaseException, and Django specifically ignores it, so it's never caught by its signal handler.
Activity
dcramer commentedon Oct 27, 2015
this sounds like noise to me -- how is it different than things like the client disconnecting before the response finishes streaming?
mattrobenolt commentedon Oct 27, 2015
That shouldn't trigger a
SystemExit.This timeout is specifically when gunicorn kills the worker because it was taking too long to respond. Maybe a busy loop or something like that. So this goes unnoticed.
If the client disconnects, it should be an
IOErroror something akin to that. I'd have to investigate exactly what happens in that case a bit more. But it's unlikely that it's aSystemExitsince that's telling the process to die.dcramer commentedon Oct 27, 2015
The problem is that "SystemExit" is not a generic error. It'd be akin to us logging an error whenever you called sys.exit(1), which doesnt make much sense. We have the syshook handlers which capture things that get bubbled up (and raise SystemExit should), so I'm not sure what case this is specifically trying to cater towards.
mattrobenolt commentedon Oct 27, 2015
For posterity:
Run with
gunicorn timeout:application -t 1mattrobenolt commentedon Oct 27, 2015
I think this is different since it's happening within the wsgi middleware, so the
sys.exit()would have to have been called at some point within the request. Which... imo probably worth logging, but could be wrong. Not sure when someone would ever legitimately do that.I'll investigate this and see if that's triggered. I forgot about that.
The specific case is a view in your app that is timing out and the process is getting killed without you knowing about it since nothing was logged. This would log it and log where it was killed from.
For example, the stacktrace looks like this:
dcramer commentedon Oct 27, 2015
Oh is this specifically because we ignore that error today?
I personally dont like catering to gunicorn, but its probably fine to capture all in the middleware
mattrobenolt commentedon Oct 27, 2015
We don't ignore it specifically, but it's not caught by
Exceptionsince it's stemming fromBaseException, and Django specifically ignores it, so it's never caught by its signal handler.We specifically miss it here: https://github.com/getsentry/raven-python/blob/master/raven/middleware.py#L36, https://github.com/getsentry/raven-python/blob/master/raven/middleware.py#L43, and https://github.com/getsentry/raven-python/blob/master/raven/middleware.py#L52 since it's not an
Exception.My proposal would be to basically add:
dcramer commentedon Oct 27, 2015
except (Exception, SystemExit), but thats a minor detail
You're sure other processes dont cause it to raise SystemExit when shutting down? Otherwise seems fine.
mattrobenolt commentedon Oct 27, 2015
Or actually, probably just:
mattrobenolt commentedon Oct 27, 2015
Ah, so on further investigation, we can narrow this down a bit:
A normal shut down of gunicorn from
SIGINTsendssys.exit(0)to the worker to exit cleanly, butsys.exit(1)when being killed.Gonna test against uwsgi to see what this does.
Log SystemExit in wsgi middleware when code != 0