diff --git a/lib/netutil/conn_pool.go b/lib/netutil/conn_pool.go index 04a2990f7..c3aba0076 100644 --- a/lib/netutil/conn_pool.go +++ b/lib/netutil/conn_pool.go @@ -3,6 +3,7 @@ package netutil import ( "fmt" "sync" + "time" "github.com/VictoriaMetrics/VictoriaMetrics/lib/handshake" ) @@ -70,6 +71,12 @@ func (cp *ConnPool) Get() (*handshake.BufferedConn, error) { // // Do not put broken and closed connections to the pool! func (cp *ConnPool) Put(bc *handshake.BufferedConn) { + if err := bc.SetDeadline(time.Time{}); err != nil { + // Close the connection instead of returning it to the pool, + // since it may be broken. + _ = bc.Close() + return + } cp.mu.Lock() cp.conns = append(cp.conns, bc) cp.mu.Unlock()