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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise ClientDisconnected on send() when client disconnected #2220

Merged
merged 6 commits into from Feb 12, 2024

Conversation

Kludex
Copy link
Sponsor Member

@Kludex Kludex commented Jan 20, 2024

We need to clarify this on django/asgiref@3f0147d before merging it.

馃憜 Clarified.

Also, tests are missing here.

try:
result = await app( # type: ignore[func-returns-value]
self.scope, self.receive, self.send
)
except ClientDisconnected:
...
Copy link
Sponsor Member Author

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()?

Copy link
Sponsor Member Author

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.

Copy link
Sponsor Member Author

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).

@Kludex Kludex requested a review from adriangb February 10, 2024 08:44
@Kludex
Copy link
Sponsor Member Author

Kludex commented Feb 10, 2024

I'm going to add a test before merging, but review welcome.

Copy link
Member

@adriangb adriangb left a 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

@@ -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:
...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
...
pass

I think is more common in this context?

async def test_early_response(
http_protocol_cls: HTTPProtocol,
):
async def test_disconnect_on_send(http_protocol_cls: HTTPProtocol) -> None:
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test added.

@Kludex Kludex requested a review from adriangb February 11, 2024 21:15
@Kludex Kludex merged commit 1e5f1be into master Feb 12, 2024
15 checks passed
@Kludex Kludex deleted the disconnect-http-on-send branch February 12, 2024 06:36
ninoseki added a commit to ninoseki/uvicorn that referenced this pull request Mar 16, 2024
Kludex added a commit that referenced this pull request Mar 19, 2024
* chore: revert #2220

* Don't revert the receive changes

---------

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
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.

None yet

2 participants