1
0
mirror of https://github.com/redis/go-redis.git synced 2025-12-18 23:34:11 +03:00

fix(retry): Add retry mechanism for NOREPLICAS error (#3647)

This commit is contained in:
ofekshenawa
2025-12-10 18:14:05 +02:00
committed by GitHub
parent e4965ea90b
commit 4edf494293
5 changed files with 78 additions and 12 deletions

View File

@@ -124,6 +124,9 @@ func shouldRetry(err error, retryTimeout bool) bool {
if proto.IsTryAgainError(err) {
return true
}
if proto.IsNoReplicasError(err) {
return true
}
// Fallback to string checking for backward compatibility with plain errors
s := err.Error()
@@ -145,6 +148,9 @@ func shouldRetry(err error, retryTimeout bool) bool {
if strings.HasPrefix(s, "MASTERDOWN ") {
return true
}
if strings.HasPrefix(s, "NOREPLICAS ") {
return true
}
return false
}
@@ -342,6 +348,14 @@ func IsOOMError(err error) bool {
return proto.IsOOMError(err)
}
// IsNoReplicasError checks if an error is a Redis NOREPLICAS error, even if wrapped.
// NOREPLICAS errors occur when not enough replicas acknowledge a write operation.
// This typically happens with WAIT/WAITAOF commands or CLUSTER SETSLOT with synchronous
// replication when the required number of replicas cannot confirm the write within the timeout.
func IsNoReplicasError(err error) bool {
return proto.IsNoReplicasError(err)
}
//------------------------------------------------------------------------------
type timeoutError interface {