Skip to content

refactor(iroh): Remove lock around quinn::Endpoint again#3941

Merged
ramfox merged 4 commits intoramfox/dropped-endpointfrom
Frando/dropped-endpoint
Feb 14, 2026
Merged

refactor(iroh): Remove lock around quinn::Endpoint again#3941
ramfox merged 4 commits intoramfox/dropped-endpointfrom
Frando/dropped-endpoint

Conversation

@Frando
Copy link
Copy Markdown
Member

@Frando Frando commented Feb 13, 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 for details.

Somehow, Endpoint::watch_addrs().stream() now hangs again, couldn't spot yet how that interacts, weird.

Edit: I now know why the watch_addrs() watcher doesn't stop: It contains a local_addrs watcher, which is a watcher onto a watchable owned by Transports which is owned by the quinn::Endpoint, which with this change is not dropped at this point.

Breaking Changes

Notes & open questions

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All breaking changes documented.
    • List all breaking changes in the above "Breaking Changes" section.
    • Open an issue or PR on any number0 repos that are affected by this breaking change. Give guidance on how the updates should be handled or do the actual updates themselves. The major ones are:

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 13, 2026

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh/pr/3941/docs/iroh/

Last updated: 2026-02-13T23:58:37Z

@n0bot n0bot bot added this to iroh Feb 13, 2026
@github-project-automation github-project-automation bot moved this to 🚑 Needs Triage in iroh Feb 13, 2026
@Frando Frando changed the title refactor: use change in quinn to remove lock around endpoint again refactor(iroh): Remove lock around quinn::Endpoint again Feb 13, 2026
@Frando Frando marked this pull request as ready for review February 13, 2026 12:51
“ramfox” and others added 2 commits February 13, 2026 17:26
## 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 ramfox merged commit 99f337c into ramfox/dropped-endpoint Feb 14, 2026
46 of 53 checks passed
@github-project-automation github-project-automation bot moved this from 🚑 Needs Triage to ✅ Done in iroh Feb 14, 2026
@ramfox ramfox deleted the Frando/dropped-endpoint branch February 14, 2026 00:17
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.
ramfox pushed a commit that referenced this pull request Feb 17, 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants