Conversation
|
Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh/pr/3879/docs/iroh/ Last updated: 2026-02-19T18:23:46Z |
64018a2 to
af81061
Compare
Member
This is a self-reference in the PR description? |
matheus23
reviewed
Feb 12, 2026
Frando
reviewed
Feb 12, 2026
Frando
reviewed
Feb 12, 2026
f5440f4 to
c9aaa59
Compare
353e3f0 to
b298b42
Compare
ramfox
pushed a commit
that referenced
this pull request
Feb 13, 2026
## Description Based on #3941 which is based on #3879 * Add `Endpoint::closed`, which returns a `CancellationToken` that is cancelled once the endpoint is closing * Document watcher behavior with regards to closing the endpoint * Fix test ## Breaking Changes <!-- Optional, if there are any breaking changes document them, including how to migrate older code. --> ## Notes & open questions * Instead of returning a `CancellationToken` we could make this an `async fn`, however to me it looks quite useful to get a `CancellationToken` and be able to use `tokio::spawn(endpoint_closed.run_until_cancelled_owned(async move { .. })))` * The cancellation token is cancelled when `Endpoint::close` *starts*, not when it *ends*. I wasn't sure what expected behavior is here. I opted for start because this guarantees that the endpoint is fully usable until then.
ramfox
pushed a commit
that referenced
this pull request
Feb 14, 2026
## Description Based on #3879 Depends on n0-computer/noq#426 With n0-computer/noq#426 the quinn::EndpointDriver stops once the quinn::Endpoint is closed and all connections are drained. Thus we don't need the `RwLock` around the `quinn::Endpoint` anymore. See [this thread](#3879 (comment)) for details. * Add `Endpoint::closed`, which returns a `CancellationToken` that is cancelled once the endpoint is closing * Document watcher behavior with regards to closing the endpoint * Fix test ## Notes & open questions * Instead of returning a `CancellationToken` we could make this an `async fn`, however to me it looks quite useful to get a `CancellationToken` and be able to use `tokio::spawn(endpoint_closed.run_until_cancelled_owned(async move { .. })))` * The cancellation token is cancelled when `Endpoint::close` *starts*, not when it *ends*. I wasn't sure what expected behavior is here. I opted for start because this guarantees that the endpoint is fully usable until then.
…cept` future if the future is ever polled
## Description Based on #3879 Depends on n0-computer/noq#426 With n0-computer/noq#426 the quinn::EndpointDriver stops once the quinn::Endpoint is closed and all connections are drained. Thus we don't need the `RwLock` around the `quinn::Endpoint` anymore. See [this thread](#3879 (comment)) for details. * Add `Endpoint::closed`, which returns a `CancellationToken` that is cancelled once the endpoint is closing * Document watcher behavior with regards to closing the endpoint * Fix test ## Notes & open questions * Instead of returning a `CancellationToken` we could make this an `async fn`, however to me it looks quite useful to get a `CancellationToken` and be able to use `tokio::spawn(endpoint_closed.run_until_cancelled_owned(async move { .. })))` * The cancellation token is cancelled when `Endpoint::close` *starts*, not when it *ends*. I wasn't sure what expected behavior is here. I opted for start because this guarantees that the endpoint is fully usable until then.
## Description Based on #3879 This makes `Endpoint::closed` return a named future instead of `CancellationToken` to not depend on `tokio_util` in our public API.
a9c255f to
2b56e64
Compare
2b56e64 to
cd86c5f
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
closes #3867
relies on #3924
Alot of finagaling needed to happen to ensure that when the Endpoint is dropped, it's underlying resources are cleaned up ASAP.
First, added a custom
Runtimethat wraps spawned tasks in aCancellationToken. This allows for both graceful shutdown (which does not use the cancel token, but instead waits for tasks to finish naturally) and ungraceful abort (which uses the cancel token to stop all running tasks)Second, thequinn::Endpointinside of theHandleneeded to be wrapped in anArc<RwLock<Option>>, so we could take the underlyingquinn::Endpointand drop it onHandle::closeand the newHandle::abortmethod. This value should only be written once (during the close or abort), and so the read lock should never be in contention.This was fixed in
iroh-quinn, so no need to add a rw lockThird, wrote a new
Handle::abortmethod that is sync and does not wait for graceful clean up after cancelling tokens, before dropping the underlyingquinn::Endpointor aborting any runtime tasks.Fourth, in order to ensure that the
Endpointis only "aborted" on the last clone of the endpoint, the meat of theEndpointhas been moved into anEndpointInnerthat is wrapped in anArc. When theArcis finally dropped, theDropimpl onEndpointInneris called, which callsHandle::abort, if theEndpointwas not gracefully closed before dropping.The last major change is the work that needed to be done onAccept. The call toquinn::Endpoint::Accepttakes a reference to thequinn::Endpoint, but since it is now behind aRwLockit can not longer be borrowed. This refactor turned theAcceptinto aBoxFuture, whose closure owns a clone of thequinn::Endpoint.Finally, let's make sure that we drop any references to address lookup services on close.
NOTE: While I used claude to code-review/double check assumptions while working on this PR in general, theAcceptchanges were where I relied on AI the most to give me a "sensible" work around to the self-reference problem I was facing when making the RwLock refactors. I would love some feedback here if this is an acceptable solution.No longer necessary since we do not wrap the quinn::Endpoint in a rwlock any more
Breaking Changes
New behavioral change! Then
Endpointdoes not do ANY best-effort to close connections gracefully before dropping. This makes it even more important to callEndpoint::closein all cases.This change (that prevents the underlying
quinn::Endpointto do it's best to wait/send close frames before shutting down) has already highlighted in tests how much more brittle it is to drop the endpoint without callingclosefirst.Change checklist