p2p: fix node abort when a request races connection shutdown - #691
p2p: fix node abort when a request races connection shutdown#691redsh4de wants to merge 2 commits into
Conversation
|
Running this for about a week, no more panics on my end |
|
I haven't approved and merged this yet as I want to add a way to disarm the client service so it doesn't keep holding permits/locks if it isn't going to be called after poll_ready. I think we'll need to add an extension trait to tower::Service for this though to allow it to be used generically. I will get round to doing this before the next release unless you have a good idea on how this could be done. |
|
This change avoids reserving permits in |
|
That removes the need for the semaphore completely and stops people from being able to make decisions on readiness. I'll have to think about it. |
What
Fixes a panic that aborts the node when a request is sent as its connection is shutting down
Why
Client::poll_readyreserves an mpsc permit, and outstanding permits can still send afterReceiver::close.Connection::shutdowndrains withtry_recv, which can't wait for them, so a request that races shutdown is stranded and itsoneshot::Senderdropped - panickingInfallibleOneshotReceiver.From
Receiver::closedocs:Where
p2p/p2p-coreHow
Connection::shutdownwithrecv()untilNone, as recommended. It istokio::spawned so that the connection task can still exit right awayClient::poll_readynow checks if the connection is closed before anything else. It used to only find out by trying to reserve a channel slot, which always succeeds when a slot is already reserved, even after the peer is gone