reset deadline, fix #1562. (#1597)

* reset deadline, fix #1562.
reset deadline before we put it back to pool.

* make errcheck happy
This commit is contained in:
mxlxm 2021-09-08 01:54:17 +08:00 committed by GitHub
parent 304661c547
commit 42e07cfaea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,6 +3,7 @@ package netutil
import ( import (
"fmt" "fmt"
"sync" "sync"
"time"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/handshake" "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! // Do not put broken and closed connections to the pool!
func (cp *ConnPool) Put(bc *handshake.BufferedConn) { 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.mu.Lock()
cp.conns = append(cp.conns, bc) cp.conns = append(cp.conns, bc)
cp.mu.Unlock() cp.mu.Unlock()