Compare commits

...

3 Commits

Author SHA1 Message Date
Kent Wang 78d37bbdeb
Merge 550b25c20e into 930d904205 2024-11-14 13:28:12 -08:00
Kent Wang 550b25c20e
Merge branch 'master' into conn-checker 2024-07-17 17:12:21 +08:00
Kent Wang b802a3e5e3 Add ConnChecker to customize conn health check 2024-07-03 21:21:56 +08:00
2 changed files with 11 additions and 0 deletions

View File

@ -68,6 +68,7 @@ type Options struct {
MaxActiveConns int
ConnMaxIdleTime time.Duration
ConnMaxLifetime time.Duration
ConnChecker func(net.Conn) error
}
type lastDialErrorWrap struct {
@ -513,6 +514,12 @@ func (p *ConnPool) isHealthyConn(cn *Conn) bool {
return false
}
if p.cfg.ConnChecker != nil {
if err := p.cfg.ConnChecker(cn.netConn); err != nil {
return false
}
}
cn.SetUsedAt(now)
return true
}

View File

@ -139,6 +139,9 @@ type Options struct {
// Default is to not close idle connections.
ConnMaxLifetime time.Duration
// ConnChecker checks the health of a connection before returning it to the client.
ConnChecker func(net.Conn) error
// TLS Config to use. When set, TLS will be negotiated.
TLSConfig *tls.Config
@ -523,5 +526,6 @@ func newConnPool(
MaxActiveConns: opt.MaxActiveConns,
ConnMaxIdleTime: opt.ConnMaxIdleTime,
ConnMaxLifetime: opt.ConnMaxLifetime,
ConnChecker: opt.ConnChecker,
})
}