From 1d74a82fa25e48ff45336a08c12da7f7795d9ac1 Mon Sep 17 00:00:00 2001 From: Marc Gravell Date: Thu, 8 Oct 2026 11:54:09 +0100 Subject: [PATCH] docs: fix retry-category test in the custom RetryPolicy sample The ReadOnlyOnlyRetryPolicy sample in Failover.md tested the category with (fault.Flags & CommandFlags.CommandRetryReadOnly) != 0. The retry category is a 5-bit numeric field (CommandRetryNever spans it), not independent bits, so that test is also true for CommandRetryWriteChecked, CommandRetryServerAdmin and CommandRetryNever. Mask the whole field and compare instead. --- docs/Failover.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/Failover.md b/docs/Failover.md index 98d717a90..eb08eb4d4 100644 --- a/docs/Failover.md +++ b/docs/Failover.md @@ -1103,9 +1103,14 @@ public sealed class ReadOnlyOnlyRetryPolicy : RetryPolicy { public override RetryResult CanRetry(in FaultContext fault) { - // only ever retry pure reads, and only on the same server + // only ever retry read-only (or safer) commands, and only on the same server; + // the retry category is a small numeric field inside CommandFlags, not a set of + // independent bits, so mask the whole field (CommandRetryNever spans it) and + // compare, rather than testing a single category value with "& != 0" + var category = fault.Flags & CommandFlags.CommandRetryNever; if (fault.ErrorKind == RedisErrorKind.Loading - && (fault.Flags & CommandFlags.CommandRetryReadOnly) != 0) + && category != 0 // uncategorised commands are never retried + && category <= CommandFlags.CommandRetryReadOnly) { return RetryResult.SameServer; }