Skip to content

Commit 3345fd1

Browse files
committed
fix(auth): check err on close conn
1 parent 5228611 commit 3345fd1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

redis.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,17 @@ func (c *baseClient) onAuthenticationErr(poolCn *pool.Conn) func(err error) {
312312
return func(err error) {
313313
if err != nil {
314314
if isBadConn(err, false, c.opt.Addr) {
315-
c.connPool.CloseConn(poolCn)
315+
// Close the connection to force a reconnection.
316+
err := c.connPool.CloseConn(poolCn)
317+
if err != nil {
318+
internal.Logger.Printf(context.Background(), "redis: failed to close connection: %v", err)
319+
// try to close the network connection directly
320+
// so that no resource is leaked
321+
err := poolCn.Close()
322+
if err != nil {
323+
internal.Logger.Printf(context.Background(), "redis: failed to close network connection: %v", err)
324+
}
325+
}
316326
}
317327
internal.Logger.Printf(context.Background(), "redis: re-authentication failed: %v", err)
318328
}

0 commit comments

Comments
 (0)