fix(registrar): ensure onDisconnect respects notifyOnLimitedConnection#3376
fix(registrar): ensure onDisconnect respects notifyOnLimitedConnection#3376paschal533 wants to merge 3 commits intolibp2p:mainfrom
Conversation
|
gentle bump @dozyio for review |
packages/libp2p/src/registrar.ts
Outdated
There was a problem hiding this comment.
this also needs the fix and a test added 🙏
| // was previously added to the filter (which happens on onConnect). | ||
| // This ensures limited connections that were never notified via | ||
| // onConnect don't trigger onDisconnect. | ||
| if (topology.filter != null && topology.filter.has(remotePeer) !== true) { |
There was a problem hiding this comment.
| if (topology.filter != null && topology.filter.has(remotePeer) !== true) { | |
| if (topology.filter?.has(remotePeer) !== true) { |
follows style from other handler methods
|
Hi @tabcat , Thanks for the review. I've applied the fix to line 244 in However, I need to keep the explicit null check ( The optional chaining pattern doesn't work correctly for topologies without filters // This breaks topologies without filters:
if (topology.filter?.has(peer) !== true) { return }
// When filter is undefined: undefined !== true → true → always returns early!This causes the test "should call topology onConnect handler for limited connection when explicitly The explicit check handles all three cases correctly: if (topology.filter != null && topology.filter.has(peer) !== true) { return }
// When filter is undefined: false && ... → false → calls handler ✓
// When filter exists but peer not in it: true && true → true → skips ✓
// When filter exists and peer is in it: true && false → false → calls handler ✓The style difference exists because:
All tests now pass including the limited connection tests. Let me know if you'd prefer a different |
Title
fix(registrar): ensure onDisconnect respects notifyOnLimitedConnection
Description
Fixed an inconsistency in topology notification where
onDisconnectcould fire for connections that never triggeredonConnect.When a topology has
notifyOnLimitedConnectionunset (defaultfalse), connections with limits (like circuit relay connections used for WebRTC SDP signaling) correctly skiponConnect. However, when these connections closed,onDisconnectwas still being called due to 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.
Fixes #2647
Fixes #2369
Notes & open questions
transport-webrtcbecause circuit relay v2 connections already haveconnection.limitsset. The bug was purely in the registrar's disconnect notification logic.undefined === false → false) is a subtle JS gotcha that allowed this to go undetected.Change checklist