Skip to content

Commit

Permalink
fix: Defer resource usage cleanup until the very end (#3042)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo committed Nov 19, 2024
1 parent df02f4d commit ae0d78a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions p2p/protocol/circuitv2/relay/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion p2p/transport/webtransport/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Expand Down

0 comments on commit ae0d78a

Please sign in to comment.