From 5bba252ffb656c8217dc535d4160e9775b0b162c Mon Sep 17 00:00:00 2001 From: Aravind Yeduvaka Date: Wed, 26 Feb 2020 10:18:29 -0800 Subject: [PATCH] Fixing a bug where READONLY is run before AUTH. Causes MOVED errors when reconnecting to Clustered Slaves. --- src/StackExchange.Redis/PhysicalBridge.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/StackExchange.Redis/PhysicalBridge.cs b/src/StackExchange.Redis/PhysicalBridge.cs index 7b59481ef..8106266af 100644 --- a/src/StackExchange.Redis/PhysicalBridge.cs +++ b/src/StackExchange.Redis/PhysicalBridge.cs @@ -1200,15 +1200,20 @@ private WriteResult WriteMessageToServerInsideWriteLock(PhysicalConnection conne if (!connection.TransactionActive) { - var readmode = connection.GetReadModeCommand(isMasterOnly); - if (readmode != null) + // If we are executing AUTH, it means we are still unauthenticated + // Setting READONLY before AUTH always fails but we think it succeeded since + // we run it as Fire and Forget. + if (cmd != RedisCommand.AUTH) { - connection.EnqueueInsideWriteLock(readmode); - readmode.WriteTo(connection); - readmode.SetRequestSent(); - IncrementOpCount(); + var readmode = connection.GetReadModeCommand(isMasterOnly); + if (readmode != null) + { + connection.EnqueueInsideWriteLock(readmode); + readmode.WriteTo(connection); + readmode.SetRequestSent(); + IncrementOpCount(); + } } - if (message.IsAsking) { var asking = ReusableAskingCommand;