-
Notifications
You must be signed in to change notification settings - Fork 171
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
fix(iroh-net)!: improve magicsock's shutdown story #2227
fix(iroh-net)!: improve magicsock's shutdown story #2227
Conversation
I haven't gone through all the pain of trying to implement this, so might have this wrong. Could you explain why the dropping of The most recent comment at quinn-rs/quinn#1828 (comment) also seems to think that dropping of the Also I think once Quinn drops the |
Signal on drop has two problems mainly:
let ep1 = MagicEndpoint::new();
let ep2 = ep1.clone();
ep2.close().await // this is a deadlock Keeping track of clones is not easy so even in the presence of a big warning to users, I find such an API honestly unacceptable. It's not like a function
let msock = MagicSock::new();
let quinn_ep = quinn::Endpoint::new_with_abstract_socket(msock.clone());
drop(quinn_ep)
msock.close().await; // here the endpoint has been dropped but more
// likely than not, the `AsyncUdpSocket` **hasn't**
// been dropped yet. So more often than not you will
// _still_ get that error bubbled up as the quinn error log. The main problem is for sure the first one and it makes it IMO simply not worth it going such a convoluted path when a far simpler solution suffices |
@divagant-martian thanks for the clear summary on the problems of drop! |
Description
quinn::Endpoint::wait_idle
after close.MagicEndpoint
in an effort to express the fact that closing an endpoint is a terminal operation.MagicSock::poll_recv
to returnPoll::Pending
on close instead of an error. More info on the logic behind this change below.MagicSock::poll_send
to not error if nothing is being sent.Breaking Changes
MagicEndpoint::close
now consumes the endpoint.Notes & open questions
Shutdown
MagicSock
when quinn is done with it has proven something we can't do reliably.MagicSock
is dropped) are unreliable because the socket is held by multiple components onquinn
, including spawned detached tasks. There is no really any way to trigger the dropping of these tasks/components from outsidequinn
, and would require quite en effort to change it to happen insidequinn
.quinn
both receives and sends frames after close to read new connection attempts and gracefully reject them. This is a fair argument on their side, despite it being clearly a limitation for a reliable freeing of resources fromquinn
.quinn::endpoint: I/O error: connection closed
we have been chasing, even after thequinn::Endpoint
has been dropped. Therefore changingpoll_recv
to returnPoll::Pending
addresses this annoyance.quinn::Endpoing::wait_idle
and that the (now averted) log error inquinn
doesn't really tells us whether shutdown was or not gracefull.poll_send
andpoll_recv
: one will error on close, the other will returnPending
. I find this OK ifMagicSock
is simply a part of our implementation, but right now it's also part of our public API. I wonder if theMagicSock
makes sense to users on its own or if we should remove it from the public API.quinn
's maintainers to get a better api that allows to understand when all resources as freed has started. But this is playing the long game and we need to solve this on our end for now.Change checklist
Tests if relevant.