fix(wsgi): Do not wrap file responses when uWSGI offload-threads is e… · gitcommit90/sentry-python@c56f1f7 · GitHub
Skip to content

Commit c56f1f7

Browse files
ericapisaniclaude
andauthored
fix(wsgi): Do not wrap file responses when uWSGI offload-threads is enabled (getsentry#5556)
uWSGI uses pointer equality to detect file-like response objects eligible for its offload-threads optimization. When Sentry's WSGI middleware wraps the response in `_ScopedResponse`, the pointer changes and uWSGI's check always fails, silently disabling the offloading. This fix skips the `_ScopedResponse` wrapping when all three conditions are true: - uWSGI's `offload-threads` option is configured and > 0 - `wsgi.file_wrapper` is present in the WSGI environ (indicating the server would use it) - The response object has a `fileno` attribute (indicating it is a file-like object) When these conditions are met, the original response is returned directly, allowing uWSGI to handle offloading as intended. Fixes PY-1977 and getsentry#5107 --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8628732 commit c56f1f7

2 files changed

Lines changed: 72 additions & 2 deletions

File tree

sentry_sdk/integrations/wsgi.py

Lines changed: 24 additions & 1 deletion

tests/integrations/wsgi/test_wsgi.py

Lines changed: 48 additions & 1 deletion

0 commit comments

Comments
 (0)