StackExchange.Redis icon indicating copy to clipboard operation
StackExchange.Redis copied to clipboard

READONLY You can't write against a read only slave.

Open rcankan02 opened this issue 9 years ago • 11 comments

Hi Team,

We are using StackExchange. Redis version 1.1.603 we are noticing the below exception with it, can you please help us out

StackExchange.Redis.RedisServerException: READONLY You can't write against a read only slave. at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor1 processor, ServerEndPoint server) in C:\TeamCity\buildAgent\work\3ae0647004edff78\StackExchange.Redis\StackExchange\Redis\ConnectionMultiplexer.cs:line 2052 at StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor1 processor, ServerEndPoint server) in C:\TeamCity\buildAgent\work\3ae0647004edff78\StackExchange.Redis\StackExchange\Redis\RedisBase.cs:line 81 at StackExchange.Redis.RedisDatabase.ListLeftPush(RedisKey key, RedisValue value, When when, CommandFlags flags) in C:\TeamCity\buildAgent\work\3ae0647004edff78\StackExchange.Redis\StackExchange\Redis\RedisDatabase.cs:line 667

Thanks, Ankan

rcankan02 avatar May 31 '17 07:05 rcankan02

(edit: kinda obsolete - see later message)

When you connect, how many server endpoints did you specify, and are any of them the master? If it can't identify a master, then indeed it can't execute any commands that would attempt to mutate the data. LPUSH (via ListLeftPush) is very definitely a master-only command (the full list is in IsMasterOnly in Message.cs).

Basically: is it right? Is it possible that the only nodes it knows about are all replicas?

mgravell avatar May 31 '17 09:05 mgravell

Ah, I see; that message is coming from the server - I thought it was the client. In that case: has the configuration changed while the code was active? The library identifies the current state during connect, but there is no standard broadcast when configuration changes happen, so if you changed the master-slave configuration behind its back, it won't know.

This is perhaps something that we could improve on, meaning: if we detect READONLY on a node that we thought was writable, the library could re-initialize the configuration data.

mgravell avatar May 31 '17 09:05 mgravell

As a side note: if you have disabled the INFO command at the server, then it won't be able to determine the status correctly; if that is the case, it may be necessary to manually configure the state. Let me know if this applies to your scenario.

mgravell avatar May 31 '17 09:05 mgravell

Hi Mgravell,

Thanks for helping the issues seems to be the on mentioned on your second command. It went away after restarting our program. Please keep us posted if you take up this issue in the later Releases

Thanks, Ankan

rcankan02 avatar Jun 08 '17 09:06 rcankan02

I've been hitting this issue on Azure and had to move to a single node cluster

dcarr42 avatar Nov 30 '17 19:11 dcarr42

When you saw it on Azure: what commands?

On 30 Nov 2017 7:18 p.m., "David Carr" [email protected] wrote:

I've been hitting this issue on Azure and had to move to a single node cluster

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/StackExchange/StackExchange.Redis/issues/637#issuecomment-348291989, or mute the thread https://github.com/notifications/unsubscribe-auth/AABDsA8CwzqgInoH56oDfeyuc6EY6muEks5s7v-RgaJpZM4NrRF8 .

mgravell avatar Nov 30 '17 20:11 mgravell

Combo of hget hvalsha.....using asp.net caching middleware. Whatever version ships with 2.0.0

dcarr42 avatar Dec 01 '17 16:12 dcarr42

Hi Mgravell,

Can you please let us know if the issue had been addressed in the latest version.

rcankan02 avatar Jan 02 '18 09:01 rcankan02

@mgravell We ran into this a few days ago, we have a 2 node redis setup, and the primary node (read/write) failed over to the replica, which worked seamlessly, no issues. The replica became a read/write node immediately.

We then revived the primary node and it put the other node back into read only mode at which point the stack exchange redis library began failing with errors that we could not execute a write command on a read only replica.

We added code to catch the exception check for this messaging and call configure to reset the connection multiplexer and this works fine, but perhaps this type of thing could be baked into a future version of this library?

jjxtra avatar Jan 07 '22 21:01 jjxtra

Yes, this has come up a few times lately, and I'll try to find opportunity to explicitly handle -READONLY and interpret it as a topology change that requires a reconfiguration sweep

mgravell avatar Jan 08 '22 10:01 mgravell

Thank you. We ended up adding another feature to recreate any pub/sub queues too. Is this necessary when calling configure or do they get recreated automatically?

I don't know if you're open to using Polly but that's what we used to catch the exception and implement a retry with the configure called first.

jjxtra avatar Jan 08 '22 23:01 jjxtra