fix(registrar): ensure onDisconnect is not called when onConnect was skipped for limited connections#3375
Closed
paschal533 wants to merge 1 commit intolibp2p:mainfrom
Closed
fix(registrar): ensure onDisconnect is not called when onConnect was skipped for limited connections#3375paschal533 wants to merge 1 commit intolibp2p:mainfrom
paschal533 wants to merge 1 commit intolibp2p:mainfrom
Conversation
Fixes the inconsistency where topologies with notifyOnLimitedConnection: false would not receive onConnect events for limited connections, but would still receive onDisconnect events when those connections closed. This issue was particularly problematic for WebRTC browser-to-browser connections, where a temporary circuit relay connection is established just for SDP signaling. When this connection closes, protocols like GossipSub would receive spurious disconnect events even though they never received a connect event. The root cause was in the _onDisconnect handler's filter check: if (topology.filter?.has(remotePeer) === false) When topology.filter is undefined, this evaluates to false, allowing onDisconnect to be called even when the peer was never added to the filter during onConnect. Fixed by changing the condition to: if (topology.filter != null && topology.filter.has(remotePeer) !== true) Now the logic is: - If a topology has a filter AND the peer is not in it, skip onDisconnect - If a topology has no filter, call onDisconnect (can't track individual peers) Added comprehensive tests to verify: 1. Limited connections don't trigger onConnect or onDisconnect by default 2. Limited connections DO trigger both when notifyOnLimitedConnection: true 3. Topologies with filters only receive onDisconnect for peers in the filter Fixes libp2p#2647 Fixes libp2p#2369 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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.
What
Fixed an inconsistency in topology notification where
onDisconnectcould fire for connections that never triggeredonConnect.Problem
When a topology has
notifyOnLimitedConnectionunset (defaultfalse), connections with limits (like circuit relay connections used for WebRTC SDP signaling) correctly skiponConnect. However, when these connections close,onDisconnectwas still being called.The root cause was a logic error in
_onDisconnect:This caused spurious disconnect events in protocol handlers like GossipSub when WebRTC browser-to-browser connections use temporary relay connections for SDP exchange.
Testing
notifyOnLimitedConnection: truecovering both connect and disconnectFixes #2647
Fixes #2369