Skip to content

fix(registrar): ensure onDisconnect respects notifyOnLimitedConnection#3376

Open
paschal533 wants to merge 1 commit intolibp2p:mainfrom
paschal533:fix/sdp
Open

fix(registrar): ensure onDisconnect respects notifyOnLimitedConnection#3376
paschal533 wants to merge 1 commit intolibp2p:mainfrom
paschal533:fix/sdp

Conversation

@paschal533
Copy link

Title

fix(registrar): ensure onDisconnect respects notifyOnLimitedConnection

Description

Fixed an inconsistency in topology notification where onDisconnect could fire for connections that never triggered onConnect.

When a topology has notifyOnLimitedConnection unset (default false), connections with limits (like circuit relay connections used for WebRTC SDP signaling) correctly skip onConnect. However, when these connections closed, onDisconnect was still being called due to a logic error in _onDisconnect:

// Before: when topology.filter is undefined, this evaluates to
// undefined === false → false, so the early return never triggers
if (topology.filter?.has(remotePeer) === false) { return }

// After: explicitly checks filter exists before checking membership
if (topology.filter != null && topology.filter.has(remotePeer) !== true) { return }

This caused spurious disconnect events in protocol handlers like GossipSub when WebRTC browser-to-browser connections use temporary relay connections for SDP exchange.

Fixes #2647
Fixes #2369

Notes & open questions

  • No changes were needed in transport-webrtc because circuit relay v2 connections already have connection.limits set. The bug was purely in the registrar's disconnect notification logic.
  • The optional chaining behavior (undefined === false → false) is a subtle JS gotcha that allowed this to go undetected.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

@paschal533 paschal533 requested a review from a team as a code owner February 5, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebRTC SDP handshake connection transient? notifyOnTransient also ignore disconnection events?

1 participant