Skip to content

Commit ae0d78a

Browse files
committed
fix: Defer resource usage cleanup until the very end (#3042)
1 parent df02f4d commit ae0d78a

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

p2p/protocol/circuitv2/relay/relay.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (r *Relay) Close() error {
118118

119119
r.host.RemoveStreamHandler(proto.ProtoIDv2Hop)
120120
r.host.Network().StopNotify(r.notifiee)
121-
r.scope.Done()
121+
defer r.scope.Done()
122122
r.cancel()
123123
r.gc()
124124
if r.metricsTracer != nil {
@@ -315,7 +315,7 @@ func (r *Relay) handleConnect(s network.Stream, msg *pbv2.HopMessage) pbv2.Statu
315315
connStTime := time.Now()
316316

317317
cleanup := func() {
318-
span.Done()
318+
defer span.Done()
319319
r.mx.Lock()
320320
r.rmConn(src)
321321
r.rmConn(dest.ID)

p2p/transport/webtransport/conn.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (c *conn) allowWindowIncrease(size uint64) bool {
7171
// It must be called even if the peer closed the connection in order for
7272
// garbage collection to properly work in this package.
7373
func (c *conn) Close() error {
74-
c.scope.Done()
74+
defer c.scope.Done()
7575
c.transport.removeConn(c.session)
7676
err := c.session.CloseWithError(0, "")
7777
_ = c.qconn.CloseWithError(1, "")

0 commit comments

Comments
 (0)