StackExchange / StackExchange.Redis

General purpose redis client
https://stackexchange.github.io/StackExchange.Redis/
Other
5.89k stars 1.51k forks source link

"READONLY You can't write against a read only replica" errors briefly after connecting #2459

Closed eduardobr closed 1 year ago

eduardobr commented 1 year ago

For a fraction of a second after reconnecting, even connected to Redis 7 replicas, it seems SORT is being issued instead of SORT_RO, throwing StackExchange.Redis.RedisServerException. I will guess that this is because SE.Redis may take some time to know it is actually a Redis 7 instance and switch from SORT to the supported SORT_RO, makes sense? This probably affects many areas of SE.Redis where it changes behavior depending on server version.

I see the ConnectionMultiplexer has a DefaultVersion property, which raises 2 questions:

Edit: I can see there was some work on this area here (https://github.com/StackExchange/StackExchange.Redis/pull/2191) with intentions to handle SORT_RO detection nicely, so maybe we have a bug?

NickCraver commented 1 year ago

We detect which version we're in as part of the connection, yes - so briefly we'll assume lower. Setting your connection explicitly to version 7 from the start would indeed fix this as the assumption changes to 7, but we'd still upgrade to 8 in your scenario as part of the handshake, just as we upgrade to 7 today.

So the setting is just "until we connect and know for sure, assume this". Currently that's version 3 (maximum compatibility), upgrading to 7. In your future scenario, that'd be 7 (from config, instead of default 3) upgrading to 8.

eduardobr commented 1 year ago

Thank you @NickCraver!