1
0
mirror of https://github.com/redis/go-redis.git synced 2025-12-05 06:22:07 +03:00

fix(logs): panic on nil error in handoffWorkerManager closeConnFromRequest (#3633)

This commit is contained in:
ccoVeille
2025-12-03 09:43:29 +01:00
committed by GitHub
parent 7a345ab467
commit eeea45c8f8
2 changed files with 21 additions and 11 deletions

View File

@@ -288,19 +288,29 @@ func OperationNotTracked(connID uint64, seqID int64) string {
// Connection pool functions // Connection pool functions
func RemovingConnectionFromPool(connID uint64, reason error) string { func RemovingConnectionFromPool(connID uint64, reason error) string {
message := fmt.Sprintf("conn[%d] %s due to: %v", connID, RemovingConnectionFromPoolMessage, reason) metadata := map[string]interface{}{
return appendJSONIfDebug(message, map[string]interface{}{
"connID": connID, "connID": connID,
"reason": reason.Error(), "reason": "unknown", // this will be overwritten if reason is not nil
}) }
if reason != nil {
metadata["reason"] = reason.Error()
}
message := fmt.Sprintf("conn[%d] %s due to: %v", connID, RemovingConnectionFromPoolMessage, reason)
return appendJSONIfDebug(message, metadata)
} }
func NoPoolProvidedCannotRemove(connID uint64, reason error) string { func NoPoolProvidedCannotRemove(connID uint64, reason error) string {
message := fmt.Sprintf("conn[%d] %s due to: %v", connID, NoPoolProvidedMessageCannotRemoveMessage, reason) metadata := map[string]interface{}{
return appendJSONIfDebug(message, map[string]interface{}{
"connID": connID, "connID": connID,
"reason": reason.Error(), "reason": "unknown", // this will be overwritten if reason is not nil
}) }
if reason != nil {
metadata["reason"] = reason.Error()
}
message := fmt.Sprintf("conn[%d] %s due to: %v", connID, NoPoolProvidedMessageCannotRemoveMessage, reason)
return appendJSONIfDebug(message, metadata)
} }
// Circuit breaker functions // Circuit breaker functions

View File

@@ -501,9 +501,9 @@ func (hwm *handoffWorkerManager) closeConnFromRequest(ctx context.Context, reque
internal.Logger.Printf(ctx, logs.RemovingConnectionFromPool(conn.GetID(), err)) internal.Logger.Printf(ctx, logs.RemovingConnectionFromPool(conn.GetID(), err))
} }
} else { } else {
err := conn.Close() // Close the connection if no pool provided errClose := conn.Close() // Close the connection if no pool provided
if err != nil { if errClose != nil {
internal.Logger.Printf(ctx, "redis: failed to close connection: %v", err) internal.Logger.Printf(ctx, "redis: failed to close connection: %v", errClose)
} }
if internal.LogLevel.WarnOrAbove() { if internal.LogLevel.WarnOrAbove() {
internal.Logger.Printf(ctx, logs.NoPoolProvidedCannotRemove(conn.GetID(), err)) internal.Logger.Printf(ctx, logs.NoPoolProvidedCannotRemove(conn.GetID(), err))