From eeea45c8f80cec31392f4a5b9702f2cff71f16d1 Mon Sep 17 00:00:00 2001 From: ccoVeille <3875889+ccoVeille@users.noreply.github.com> Date: Wed, 3 Dec 2025 09:43:29 +0100 Subject: [PATCH] fix(logs): panic on nil error in handoffWorkerManager closeConnFromRequest (#3633) --- .../maintnotifications/logs/log_messages.go | 26 +++++++++++++------ maintnotifications/handoff_worker.go | 6 ++--- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/internal/maintnotifications/logs/log_messages.go b/internal/maintnotifications/logs/log_messages.go index 34cb1692..44ae0060 100644 --- a/internal/maintnotifications/logs/log_messages.go +++ b/internal/maintnotifications/logs/log_messages.go @@ -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 diff --git a/maintnotifications/handoff_worker.go b/maintnotifications/handoff_worker.go index 5b60e39b..53f28f49 100644 --- a/maintnotifications/handoff_worker.go +++ b/maintnotifications/handoff_worker.go @@ -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))