Skip to content

Raise ClientDisconnected on send() when client disconnected#2220

Merged
Kludex merged 6 commits intomasterfrom
disconnect-http-on-send
Feb 12, 2024
Merged

Raise ClientDisconnected on send() when client disconnected#2220
Kludex merged 6 commits intomasterfrom
disconnect-http-on-send

Conversation

@Kludex
Copy link
Copy Markdown
Owner

@Kludex Kludex commented Jan 20, 2024

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

👆 Clarified.

Also, tests are missing here.

@Kludex Kludex force-pushed the disconnect-http-on-send branch from 71c0a00 to fd088ff Compare February 10, 2024 08:39
self.scope, self.receive, self.send
)
except ClientDisconnected:
...
Copy link
Copy Markdown
Owner 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
Copy Markdown
Owner 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
Copy Markdown
Owner 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
Copy Markdown
Owner Author

Kludex commented Feb 10, 2024

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

Copy link
Copy Markdown
Contributor

@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

Comment thread uvicorn/protocols/http/h11_impl.py Outdated
self.scope, self.receive, self.send
)
except ClientDisconnected:
...
Copy link
Copy Markdown
Contributor

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?

@Kludex Kludex force-pushed the disconnect-http-on-send branch from aa46d41 to c19dae7 Compare February 11, 2024 21:14
async def test_early_response(
http_protocol_cls: HTTPProtocol,
):
async def test_disconnect_on_send(http_protocol_cls: HTTPProtocol) -> None:
Copy link
Copy Markdown
Owner 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
@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.

2 participants