-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Raising a 412 on a Sanic handler causes a wait period and maybe a ReadTimeout exception on clients #2575
Comments
I can confirm this. Looks like @Tronic had an intention to come back here at some point:
|
@ahopkins Any idea on why exactly Sanic strips headers on conditional responses (304, 412)? Shouldn't the app just not set the entity headers if not needed? Looks like the function being called does what that TODO says, anyway, but it wasn't originally my work. |
Nope. I want to dig into that and figure out where/when it was added for context. Also I want to dig into the RFC because what I understand there shouldn't be any header removal for 412. I didn't see anything that would indicate a restriction in content or headers allowed. But I only had time to take a cursory look at the earlier RFC and nine of the revisions. |
Fix is coming in the next release. |
Hi @ahopkins, FYI: content-length was removed for 412 responses since #1127 Other than the PR description itself, there was not much discussion about the header removal for 412 responses, nor were any of the referenced materials/RFC explaining why the I also asked chatGPT and got:
I would assume that was a mistake and believe we can safely remove it. |
Describe the bug
When raising a 412, clients are left waiting to read until a timeout is triggered and a ReadTimeout exception may occur.
Code snippet
The issue can be reproduced with code for an app as minimal as:
The client can be Postman, bash curl, or even a Python fetch:
The above client code will print:
Expected behavior
The client should quickly receive the 412 response.
Environment (please complete the following information):
Additional context
What I think is happening is that Sanic strips the headers on 412 responses, including the
content-type
header. However, and contrary to what happens for a 304 code, Sanic will still send the 412 response body to the client, which causes the latter to wait for more data, without knowing the actual size of the response, until it times out.The text was updated successfully, but these errors were encountered: