Skip to content
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

Fix 'no response returned' RuntimeError during cancellation in BaseHTTPMiddleware #2519

Conversation

jonathanslenders
Copy link

@jonathanslenders jonathanslenders commented Feb 16, 2024

Fixes: #2516

If an incoming request is disconnected before a response gets produced, don't raise a RuntimeError. This fixes a race condition that occurs when many BaseHTTPMiddleware instances are wrapped within each other and the client (e.g., web browser) disconnects before the start of the response has been produced by the endpoint.

An alternative fix, possibly better, would be to always return a dummy Response and never raise the RuntimeError, regardless of whether _is_disconnected is set.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

…TPMiddleware.

If an incoming request is disconnected before a response gets produced, don't
raise a RuntimeError.
@Kludex
Copy link
Sponsor Member

Kludex commented Mar 21, 2024

This doesn't look like a reasonable fix for the issue.

@Kludex Kludex closed this Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RuntimeError("No response returned") in BaseHTTPMiddleware
2 participants