From de69b4915645e8c65f27badec3597d5a1d40e7c3 Mon Sep 17 00:00:00 2001 From: Bhargav Dodla Date: Thu, 14 Nov 2024 12:19:14 -0800 Subject: [PATCH] fix: Fixed issue with context cancelled error leading to connection spikes on Master --- error.go | 9 +++++++++ osscluster.go | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/error.go b/error.go index 9b348193a..a7bf159c2 100644 --- a/error.go +++ b/error.go @@ -38,6 +38,15 @@ type Error interface { var _ Error = proto.RedisError("") +func isContextError(err error) bool { + switch err { + case context.Canceled, context.DeadlineExceeded: + return true + default: + return false + } +} + func shouldRetry(err error, retryTimeout bool) bool { switch err { case io.EOF, io.ErrUnexpectedEOF: diff --git a/osscluster.go b/osscluster.go index 72e922a80..a60a6fa78 100644 --- a/osscluster.go +++ b/osscluster.go @@ -1344,7 +1344,9 @@ func (c *ClusterClient) processPipelineNode( _ = node.Client.withProcessPipelineHook(ctx, cmds, func(ctx context.Context, cmds []Cmder) error { cn, err := node.Client.getConn(ctx) if err != nil { - node.MarkAsFailing() + if !isContextError(err) { + node.MarkAsFailing() + } _ = c.mapCmdsByNode(ctx, failedCmds, cmds) setCmdsErr(cmds, err) return err