diff --git a/p2p/protocol/circuitv2/relay/relay.go b/p2p/protocol/circuitv2/relay/relay.go index 2ee237d97b..326d17781b 100644 --- a/p2p/protocol/circuitv2/relay/relay.go +++ b/p2p/protocol/circuitv2/relay/relay.go @@ -118,7 +118,7 @@ func (r *Relay) Close() error { r.host.RemoveStreamHandler(proto.ProtoIDv2Hop) r.host.Network().StopNotify(r.notifiee) - r.scope.Done() + defer r.scope.Done() r.cancel() r.gc() if r.metricsTracer != nil { @@ -315,7 +315,7 @@ func (r *Relay) handleConnect(s network.Stream, msg *pbv2.HopMessage) pbv2.Statu connStTime := time.Now() cleanup := func() { - span.Done() + defer span.Done() r.mx.Lock() r.rmConn(src) r.rmConn(dest.ID) diff --git a/p2p/transport/webtransport/conn.go b/p2p/transport/webtransport/conn.go index 0525124711..d914398e0e 100644 --- a/p2p/transport/webtransport/conn.go +++ b/p2p/transport/webtransport/conn.go @@ -71,7 +71,7 @@ func (c *conn) allowWindowIncrease(size uint64) bool { // It must be called even if the peer closed the connection in order for // garbage collection to properly work in this package. func (c *conn) Close() error { - c.scope.Done() + defer c.scope.Done() c.transport.removeConn(c.session) err := c.session.CloseWithError(0, "") _ = c.qconn.CloseWithError(1, "")