StackExchange / StackExchange/StackExchange.Redis

Sentinel failover for hung master server

Open
#1,670 7 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

⚙️ area:connection ⚙️ area:sentinel
Dominant language
C#
Stars
6.2k
Forks
1.6k
Avg merge
1d 15h
Merged PRs (30d)
43

Description

Hello all,
We are in the process of trying to get a production-ready implementation of Redis/Sentinel, .NET core 3 and SE.Redis 2.2.4 working. We have 3 sentinels and 3 Redis servers running in docker containers. I am using what I think is standard initialization with certificate validation:

ConfigurationOptions redisOptions = new ConfigurationOptions(); 
redisOptions.EndPoints.Add("localhost:26379); 
redisOptions.EndPoints.Add("localhost:26380); 
redisOptions.EndPoints.Add("localhost:26381);
redisOptions.ServiceName = "testService";
redisOptions.Ssl = true;
redisOptions.TieBreaker = "";
redisOptions.AllowAdmin = true;
redisOptions.AbortOnConnectFail = false;
redisOptions.CertificateSelection += ConfigurationOptions_CertificateSelection;
redisOptions.CertificateValidation += RedisOptions_CertificateValidation;
_redis = ConnectionMultiplexer.Connect(redisOptions);

For the most part, everything seems to be working well; if I shut down the docker container for the master server, Sentinel notifies SE.Redis and the current master is changed. All I had to do was add a little retry logic to my session helper code to make it fail over gracefully.

This all works great for "downed" servers: either I take it down for maintenance or it crashes and goes away. Where it's not working so well is with a "hung" server. For example, I am using the Redis command "debug sleep 60" to test, which effectively makes the server unreachable as if it were hung (according to Sentinel docs). In this case, SE.Redis does not appear to recover, because it just keeps trying the non-responsive master, waiting for timeout, etc. Once the master comes online it starts working again.

Should I be doing something differently when I receive a RedisTimeoutException in order to compensate, or should this be working as configured? I tried calling Configure in the ConnectionFailed delegate, but that didn't work. Also tried instantiating a new ConnectionMultiplexer in the delegate with similar results.

Most of all, thanks for a great open source package, and your dedication to it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ConfigurationOptions, ConnectionMultiplexer, ConnectionFailed, and RedisTimeoutException handling in the Sentinel connection path. Reproduce the issue with Redis debug sleep and compare it with a stopped master; done means a hung master is detected and failover recovers without repeatedly waiting on the non-responsive server.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, docker, redis
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.