-
Notifications
You must be signed in to change notification settings - Fork 174
Close the QUIC datagram transports on shutdown #373
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
Open
CoryLowe5
wants to merge
1
commit into
pgjones:main
Choose a base branch
from
CoryLowe5:close-datagram-transports
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+54
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
|
|
||
| import pytest | ||
|
|
||
| from hypercorn.app_wrappers import ASGIWrapper | ||
| from hypercorn.asyncio.run import worker_serve | ||
| from hypercorn.config import Config | ||
| from ..helpers import sanity_framework | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_worker_serve_closes_datagram_transports() -> None: | ||
| pytest.importorskip("aioquic") | ||
| event_loop = asyncio.get_running_loop() | ||
| config = Config() | ||
| config.bind = [] | ||
| config.quic_bind = ["127.0.0.1:0"] | ||
| config.certfile = "tests/assets/cert.pem" | ||
| config.keyfile = "tests/assets/key.pem" | ||
| config.graceful_timeout = 0.1 | ||
| sockets = config.create_sockets() | ||
|
|
||
| transports: list[asyncio.BaseTransport] = [] | ||
| create_datagram_endpoint = event_loop.create_datagram_endpoint | ||
|
|
||
| async def _capturing(*args: object, **kwargs: object) -> tuple: | ||
| transport, protocol = await create_datagram_endpoint(*args, **kwargs) # type: ignore | ||
| transports.append(transport) | ||
| return transport, protocol | ||
|
|
||
| async def _shutdown() -> None: | ||
| return None | ||
|
|
||
| event_loop.create_datagram_endpoint = _capturing # type: ignore | ||
| try: | ||
| await worker_serve( | ||
| ASGIWrapper(sanity_framework), config, sockets=sockets, shutdown_trigger=_shutdown | ||
| ) | ||
| finally: | ||
| event_loop.create_datagram_endpoint = create_datagram_endpoint # type: ignore | ||
|
|
||
| assert transports != [] | ||
| assert all(transport.is_closing() for transport in transports) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
One cleanup edge remains here: if a later QUIC endpoint fails to start, control never reaches the
trybelow, so transports already appended todatagram_transportsstay open.I reproduced this on
dca1b5fwith two fake QUIC sockets: the firstcreate_datagram_endpoint()returned a tracked transport, the second raisedRuntimeError, and afterworker_serve()exited the first transport still reportedis_closing() == False. The new test covers normal shutdown only. Moving endpoint setup under the cleanuptry(and closing partially created transports on startup failure) would cover this path too.Disclosure: I ran the changed worker through Lumi Trace at NOQT for review context, then verified this behavior with the focused runtime repro above.
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.
Thanks for checking this. Agreed that a failure while starting a later QUIC endpoint leaves earlier transports open — but that is the existing shape of worker_serve rather than something this change adds: the TCP
serverslist a few lines up has the same gap, since setup for both runs before the cleanuptry. I kept this PR to the one observable defect (transports discarded on the normal shutdown path). Happy to do the startup-failure cleanup for both the TCP servers and the datagram transports as a follow-up if @pgjones would like it.