fix(wsgi): Do not wrap file responses when uWSGI offload-threads is enabled#5556
Merged
ericapisani merged 3 commits intomasterfrom Feb 27, 2026
Merged
Conversation
…nabled uWSGI determines whether to offload a file response using a pointer equality check on the response object. Wrapping the response in _ScopedResponse changes the pointer, causing the check to always fail and silently disabling the offloading optimization. When uWSGI offload-threads is enabled, wsgi.file_wrapper is present in the environ, and the response has a fileno attribute, return the original response directly so uWSGI's offloading works as expected. Fixes PY-1977 Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Bug Fixes 🐛Openai
Other
Documentation 📚
Internal Changes 🔧Agents
Openai Agents
Other
🤖 This preview updates automatically when you update the PR. |
Contributor
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 11.88s All tests are passing successfully. ❌ Patch coverage is 0.00%. Project has 13731 uncovered lines. Files with missing lines (180)
Generated by Codecov Action |
Co-Authored-By: Claude <noreply@anthropic.com>
ericapisani
added a commit
to getsentry/sentry-docs
that referenced
this pull request
Feb 26, 2026
Related to changes that needed to be made here: getsentry/sentry-python#5556
6 tasks
…-threads check Remove the _is_uwsgi_offload_threads_enabled() helper and the associated uWSGI import. The broader condition — skip wrapping whenever wsgi.file_wrapper is present and the response is file-like (has fileno) — is sufficient and correct since uWSGI applies file-handling optimizations beyond just offload-threads. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
_ScopedResponsewrapping when all three conditions are true:offload-threadsoption is configured and > 0wsgi.file_wrapperis present in the WSGI environ (indicating the server would use it)filenoattribute (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 #5107