Skip to content

Commit

Permalink
tcp: fix metrics for multiple calls to Close (#2953)
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Sep 24, 2024
1 parent 29265a8 commit 59c3236
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions p2p/transport/tcp/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ type tracingConn struct {
isClient bool

manet.Conn
tcpConn *tcp.Conn
tcpConn *tcp.Conn
closeOnce sync.Once
closeErr error
}

func newTracingConn(c manet.Conn, isClient bool) (*tracingConn, error) {
Expand Down Expand Up @@ -236,8 +238,11 @@ func (c *tracingConn) getDirection() string {
}

func (c *tracingConn) Close() error {
collector.ClosedConn(c, c.getDirection())
return c.Conn.Close()
c.closeOnce.Do(func() {
collector.ClosedConn(c, c.getDirection())
c.closeErr = c.Conn.Close()
})
return c.closeErr
}

func (c *tracingConn) getTCPInfo() (*tcpinfo.Info, error) {
Expand Down

0 comments on commit 59c3236

Please sign in to comment.