Exception information should be localized and passed to got_request_exception signal handlers
|Reported by:||obeattie||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
It is possible, when Django is running under Gevent (ie. via Gunicorn), for traceback information for exceptions raised while processing a request to be lost. This is because Gunicorn will throw away traceback information (deliberately, though it doesn't necessarily sound as if this is "by design"), if a switch to another greenlet occurs during processing an exception.
The specific case where this has happened for me (and subsequently destroyed traceback information about errors happening in production), is when using a patched version of psycopg2 and a signal handler (like Sentry's) which accesses the database — causing a greenlet switch. It can be replicated by using the process described in a ticket on Gunicorn's tracker.
It seems the only way to solve this is for Django to localize sys.exc_info() before calling signal handlers (which may do who knows what with regard to greenlet switching), and to pass it explicitly to signal handlers. This shouldn't cause any issues with existing signal handlers since they all must accept **kwargs anyway. I've prepared a patch, which I'll submit via a Pull Request on GitHub referencing this ticket.
On my install, before applying the patch, Django error pages would appear without traceback information; after the change, they have a proper stack trace, as expected.
Change History (5)
comment:1 Changed 4 years ago by obeattie
- Has patch set
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset