Skip to content

Commit 0136857

Browse files
committed
tcp: fix metrics for multiple calls to Close (#2953)
1 parent 921cc71 commit 0136857

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

p2p/transport/tcp/metrics.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ type tracingConn struct {
208208
isClient bool
209209

210210
manet.Conn
211-
tcpConn *tcp.Conn
211+
tcpConn *tcp.Conn
212+
closeOnce sync.Once
213+
closeErr error
212214
}
213215

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

238240
func (c *tracingConn) Close() error {
239-
collector.ClosedConn(c, c.getDirection())
240-
return c.Conn.Close()
241+
c.closeOnce.Do(func() {
242+
collector.ClosedConn(c, c.getDirection())
243+
c.closeErr = c.Conn.Close()
244+
})
245+
return c.closeErr
241246
}
242247

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

0 commit comments

Comments
 (0)