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:
@@ -288,19 +288,29 @@ func OperationNotTracked(connID uint64, seqID int64) string {
|
||||
|
||||
// Connection pool functions
|
||||
func RemovingConnectionFromPool(connID uint64, reason error) string {
|
||||
message := fmt.Sprintf("conn[%d] %s due to: %v", connID, RemovingConnectionFromPoolMessage, reason)
|
||||
return appendJSONIfDebug(message, map[string]interface{}{
|
||||
metadata := map[string]interface{}{
|
||||
"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 {
|
||||
message := fmt.Sprintf("conn[%d] %s due to: %v", connID, NoPoolProvidedMessageCannotRemoveMessage, reason)
|
||||
return appendJSONIfDebug(message, map[string]interface{}{
|
||||
metadata := map[string]interface{}{
|
||||
"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
|
||||
|
||||
@@ -501,9 +501,9 @@ func (hwm *handoffWorkerManager) closeConnFromRequest(ctx context.Context, reque
|
||||
internal.Logger.Printf(ctx, logs.RemovingConnectionFromPool(conn.GetID(), err))
|
||||
}
|
||||
} else {
|
||||
err := conn.Close() // Close the connection if no pool provided
|
||||
if err != nil {
|
||||
internal.Logger.Printf(ctx, "redis: failed to close connection: %v", err)
|
||||
errClose := conn.Close() // Close the connection if no pool provided
|
||||
if errClose != nil {
|
||||
internal.Logger.Printf(ctx, "redis: failed to close connection: %v", errClose)
|
||||
}
|
||||
if internal.LogLevel.WarnOrAbove() {
|
||||
internal.Logger.Printf(ctx, logs.NoPoolProvidedCannotRemove(conn.GetID(), err))
|
||||
|
||||
Reference in New Issue
Block a user