From 3345fd1234a808d31fd9bc72da96eac8bd7d42ae Mon Sep 17 00:00:00 2001 From: Nedyalko Dyakov Date: Wed, 14 May 2025 11:50:45 +0300 Subject: [PATCH] fix(auth): check err on close conn --- redis.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/redis.go b/redis.go index 32379d59..3d7016aa 100644 --- a/redis.go +++ b/redis.go @@ -312,7 +312,17 @@ func (c *baseClient) onAuthenticationErr(poolCn *pool.Conn) func(err error) { return func(err error) { if err != nil { if isBadConn(err, false, c.opt.Addr) { - c.connPool.CloseConn(poolCn) + // Close the connection to force a reconnection. + err := c.connPool.CloseConn(poolCn) + if err != nil { + internal.Logger.Printf(context.Background(), "redis: failed to close connection: %v", err) + // try to close the network connection directly + // so that no resource is leaked + err := poolCn.Close() + if err != nil { + internal.Logger.Printf(context.Background(), "redis: failed to close network connection: %v", err) + } + } } internal.Logger.Printf(context.Background(), "redis: re-authentication failed: %v", err) }