-
-
Notifications
You must be signed in to change notification settings - Fork 756
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
Raise ClientDisconnected
on send()
when client disconnected
#2220
Conversation
71c0a00
to
fd088ff
Compare
try: | ||
result = await app( # type: ignore[func-returns-value] | ||
self.scope, self.receive, self.send | ||
) | ||
except ClientDisconnected: | ||
... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I need to call the self.transport.close()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well... The connection_lost
callback is called, and the transport is closed there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, not adding the self.transport.close()
means that we maintain the same behavior as before (which is better).
I'm going to add a test before merging, but review welcome. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just missing a test
uvicorn/protocols/http/h11_impl.py
Outdated
@@ -412,6 +413,8 @@ async def run_asgi(self, app: "ASGI3Application") -> None: | |||
result = await app( # type: ignore[func-returns-value] | |||
self.scope, self.receive, self.send | |||
) | |||
except ClientDisconnected: | |||
... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... | |
pass |
I think is more common in this context?
aa46d41
to
c19dae7
Compare
async def test_early_response( | ||
http_protocol_cls: HTTPProtocol, | ||
): | ||
async def test_disconnect_on_send(http_protocol_cls: HTTPProtocol) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test added.
* chore: revert #2220 * Don't revert the receive changes --------- Co-authored-by: Marcelo Trylesinski <[email protected]>
We need to clarify this on django/asgiref@3f0147d before merging it.👆 Clarified.
Also, tests are missing here.