fix(request-response): debug_assert panic on last connection close - #6601
Open
procdump wants to merge 1 commit into
Open
fix(request-response): debug_assert panic on last connection close#6601procdump wants to merge 1 commit into
procdump wants to merge 1 commit into
Conversation
Recording at handle_established_* left a phantom entry when a sibling behaviour denied the connection, tripping the on_connection_closed debug_assert and mis-routing requests to a dead connection. Record on FromSwarm::ConnectionEstablished instead, so `connected` mirrors the swarm's committed set.
procdump
marked this pull request as draft
September 3, 2026 12:00
procdump
marked this pull request as ready for review
September 3, 2026 12:03
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
The problem
I've been experiencing panics with
debugbuilds in some tests around therayls blockchain, where
rust-libp2pv0.56.0is used.After some investigation it turns out
request-responserecords a connection inself.connectedfrom
handle_established_inbound_connection/handle_established_outbound_connection. Those run athandler-creation time, before the swarm has committed to the connection. In a composed
NetworkBehaviourthe derive calls each field'shandle_established_*in order and?-propagatesthe result, so a sibling ordered after
request-responsereturningConnectionDeniedaborts theconnection once we have already recorded it. Neither
ConnectionEstablishednorConnectionClosedever follows for that id, and the entry is left behind as a phantom.
That has two consequences:
self.connecteddesynchronises fromremaining_established, so closing the peer's last realconnection reports
remaining_established == 0against a non-empty list and trips thedebug_assert_eq!inon_connection_closed. This is the panic I was seeing.send_requestnotifies aconnection_idthat has no handler behind it instead of dialing the peer. This one is silent andhappens in release builds too.
What's changed
A
self.connectedentry is now created onFromSwarm::ConnectionEstablished, the first point atwhich the swarm has committed to the connection, so
connectedmirrors the swarm's established setby construction.
handle_established_*become pure handler factories with no side effects.Queued requests can no longer be preloaded into the handler at construction, so they are emitted as
ToSwarm::NotifyHandler { handler: NotifyHandler::One(connection_id), .. }instead. Same queue, sameconnection — they are just dispatched on the next
pollrather than baked into the handler.AI Assistance Disclosure
Tools used (required — write
noneif no AI was used): Claude CodeClaude Code wrote the two regression tests and helped explore alternative fixes, including checking
whether the change could affect consumers negatively. I reviewed and verified the result.
Attestation (required):
Notes & open questions
Reproducing
Keep the two new tests and restore the old recording logic:
Further steps
I also have this backported to
0.56.0here where I no longer observe the panic after a few nights of testing. In this regard if this PR gets merged is it possible that0.56.1gets published with this fix in?I'd be happy to have this resolved so share your feedback.