From 441c0e1789ba73dfada054f529977f5352c78a4a Mon Sep 17 00:00:00 2001 From: Ivan Shvedunov Date: Fri, 7 Jun 2024 11:26:15 +0400 Subject: [PATCH] identify: fix observed address handling If a connection was closed before receiving an identify response, the corresponding observed address could be wrongly removed. Patch by @sukunrt --- p2p/protocol/identify/obsaddr.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/p2p/protocol/identify/obsaddr.go b/p2p/protocol/identify/obsaddr.go index 4437c4b011..fc1c100c8e 100644 --- a/p2p/protocol/identify/obsaddr.go +++ b/p2p/protocol/identify/obsaddr.go @@ -452,6 +452,12 @@ func (o *ObservedAddrManager) removeConn(conn connMultiaddrs) { o.mu.Lock() defer o.mu.Unlock() + observedTWAddr, ok := o.connObservedTWAddrs[conn] + if !ok { + return + } + delete(o.connObservedTWAddrs, conn) + // normalize before obtaining the thinWaist so that we are always dealing // with the normalized form of the address localTW, err := thinWaistForm(o.normalize(conn.LocalMultiaddr())) @@ -467,11 +473,6 @@ func (o *ObservedAddrManager) removeConn(conn connMultiaddrs) { delete(o.localAddrs, string(localTW.Addr.Bytes())) } - observedTWAddr, ok := o.connObservedTWAddrs[conn] - if !ok { - return - } - delete(o.connObservedTWAddrs, conn) observer, err := getObserver(conn.RemoteMultiaddr()) if err != nil { return