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

Getting Failed to Nominate Master on a single server

Open beeyee0401 opened this issue 5 years ago • 3 comments

We have been using Redis on our servers for a while, and seemingly out of nowhere, one of our servers stopped creating successful connections to Redis. Some relevant notes:

  • We're on Redis version 4.0.14, the Nuget package is version 2.0.601
  • All of our other servers were connected during the time frame
  • As far as we know, this has never happened and we don't really have a way to reproduce it
  • we were getting many RedisTimeoutException alongside this "Failed to nominate master" exception
  • Our connection string looks like: syncTimeout=4000,keepAlive=20,allowAdmin=true,abortConnect=false,resolveDns=false,connectRetry=5
  • Connection count from the malfunctioning server continued to rise even though Connect/Configure was reporting the failure in the logs. We are calling Configure on a timer of 1 minute if the ConnectionMultiplexer.IsConnected property is false.

We were getting many of the errors below. Do you have any ideas for this? We are a few minor versions behind, do you think updating will solve these? Instead of Configuring the connection on failure, should we completely dispose of it and create a new one instead?

Failed to nominate master exception

{ConnectionLog:10.130.0.4:6379,name=,keepAlive=20,syncTimeout=4000,allowAdmin=True,abortConnect=False,resolveDns=False,connectRetry=5,defaultDatabase=2,$SUBSCRIBE=\r\n\r\n1 unique nodes specified\r\nRequesting tie-break from 10.130.0.4:6379 > __Booksleeve_TieBreak...\r\nAllowing endpoints 00:00:05 to respond...\r\nAwaiting task completion, IOCP: (Busy=0,Free=1400,Min=700,Max=1400), WORKER: (Busy=4,Free=1396,Min=700,Max=1400)\r\nNot all tasks completed cleanly (from ReconfigureAsync#1524, timeout 5000ms), IOCP: (Busy=0,Free=1400,Min=700,Max=1400), WORKER: (Busy=46,Free=1354,Min=700,Max=1400)\r\n10.130.0.4:6379 did not respond\r\nWaiting for tiebreakers...\r\nAwaiting task completion, IOCP: (Busy=0,Free=1400,Min=700,Max=1400), WORKER: (Busy=46,Free=1354,Min=700,Max=1400)\r\nNot all tasks completed cleanly (from NominatePreferredMaster#1761, timeout 50ms), IOCP: (Busy=0,Free=1400,Min=700,Max=1400), WORKER: (Busy=55,Free=1345,Min=700,Max=1400)\r\n10.130.0.4:6379 failed to nominate (WaitingForActivation)\r\nNo masters detected\r\nNo subscription changes necessary\r\n10.130.0.4:6379: Standalone v4.0.14, master; keep-alive: 00:00:20; int: ConnectedEstablishing; sub: n/a; not in use: DidNotRespond\r\n10.130.0.4:6379: int ops=13433, qu=0, qs=0, qc=0, wr=0, socks=3472; sub ops=0, qu=0, qs=0, qc=0, wr=0\r\nCircular op-count snapshot; int: 13433 (0.00 ops/s; spans 10s); sub:\r\nSync timeouts: 38; async timeouts: 1; fire and forget: 0; last heartbeat: 1s ago\r\n\r\nStorm log for 10.130.0.4:6379}

Here is one of the RedisConnectionException we're getting, not sure if this will be useful.

{"exception":{"ClassName":"StackExchange.Redis.RedisConnectionException","Message":"No connection is available to service this operation: GET {key}; ConnectTimeout; IOCP: (Busy=1,Free=1399,Min=700,Max=1400), WORKER: (Busy=5,Free=1395,Min=700,Max=1400), Local-CPU: 10.72%","Data":{"redis-command":"GET {key}","request-sent-status":1},"InnerException":{"ClassName":"System.AggregateException","Message":"One or more errors occurred.","Data":null,"InnerException":{"ClassName":"System.TimeoutException","Message":"ConnectTimeout","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":null,"RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2146233083,"Source":null,"WatsonBuckets":null},"HelpURL":null,"StackTraceString":null,"RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2146233088,"Source":null,"WatsonBuckets":null,"InnerExceptions":[{"ClassName":"System.TimeoutException","Message":"ConnectTimeout","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":null,"RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2146233083,"Source":null,"WatsonBuckets":null},{"ClassName":"StackExchange.Redis.RedisConnectionException","Message":"InternalFailure (None, last-recv: 1722) on 10.130.0.4:6379/Interactive, Writing/DequeueResult, last: GET, origin: WriteMessageToServerInsideWriteLock, outstanding: 40, last-read: 115s ago, last-write: 116s ago, keep-alive: 20s, state: ConnectedEstablished, mgr: 6 of 10 available, in: 0, in-pipe: 960186, out-pipe: 0, last-heartbeat: 115s ago, last-mbeat: 0s ago, global: 0s ago, v: 2.0.601.3402","Data":{"Redis-FailureType":"InternalFailure","Redis-EndPoint":"10.130.0.4:6379","Redis-Origin":"WriteMessageToServerInsideWriteLock","Redis-Outstanding-Responses":"40","Redis-Last-Read":"115s ago","Redis-Last-Write":"116s ago","Redis-Keep-Alive":"20s","Redis-Previous-Physical-State":"ConnectedEstablished","Redis-Manager":"6 of 10 available","Redis-Inbound-Bytes":"0","Redis-Inbound-Pipe-Bytes":"960186","Redis-Outbound-Pipe-Bytes":"0","Redis-Last-Heartbeat":"115s ago","Redis-Last-Multiplexer-Heartbeat":"0s ago","Redis-Last-Global-Heartbeat":"0s ago","Redis-Version":"2.0.601.3402"},"InnerException":{"ClassName":"System.Threading.ThreadAbortException","Message":"Thread was being aborted.","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":" at System.Threading.Monitor.Enter(Object obj)\r\n at StackExchange.Redis.PhysicalConnection.EnqueueInsideWriteLock(Message next) in C:\\projects\\stackexchange-redis\\src\\StackExchange.Redis\\PhysicalConnection.cs:line 484\r\n at StackExchange.Redis.PhysicalBridge.WriteMessageToServerInsideWriteLock(PhysicalConnection connection, Message message) in C:\\projects\\stackexchange-redis\\src\\StackExchange.Redis\\PhysicalBridge.cs:line 1235","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nEnter\nmscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Threading.Monitor\nVoid Enter(System.Object)","HResult":-2146233040,"Source":"mscorlib","WatsonBuckets":null},"HelpURL":null,"StackTraceString":" at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n at StackExchange.Redis.TaskExtensions.<TimeoutAfter>d__9.MoveNext() in C:\\projects\\stackexchange-redis\\src\\StackExchange.Redis\\TaskExtensions.cs:line 49\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()\r\n at StackExchange.Redis.ConnectionMultiplexer.d__72.MoveNext() in C:\projects\stackexchange-redis\src\StackExchange.Redis\ConnectionMultiplexer.cs:line 672","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nThrow\nmscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Runtime.ExceptionServices.ExceptionDispatchInfo\nVoid Throw()","HResult":-2146233088,"Source":"mscorlib","WatsonBuckets":null,"failureType":5,"commandStatus":0}]},"HelpURL":null,"StackTraceString":" at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor1 processor, ServerEndPoint server) in C:\\projects\\stackexchange-redis\\src\\StackExchange.Redis\\ConnectionMultiplexer.cs:line 2258\r\n at StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor1 processor, ServerEndPoint server) in C:\projects\stackexchange-redis\src\StackExchange.Redis\RedisBase.cs:line 54\r\n at StackExchange.Redis.RedisDatabase.StringGet(RedisKey key, CommandFlags flags) in C:\projects\stackexchange-redis\src\StackExchange.Redis\RedisDatabase.cs:line 2281}`

This is a RedisTimeoutException

{"ClassName":"StackExchange.Redis.RedisTimeoutException","Message":"The timeout was reached before the message could be written to the output buffer, and it was not sent, command=SET, timeout: 4000, outbound: 0KiB, inbound: 0KiB, active: GET {key}, next: GET {key}, inst: 0, qu: 16, qs: 68, aw: True, bw: Inactive, rs: DequeueResult, ws: Writing, in: 0, in-pipe: 1022427, out-pipe: 0, serverEndpoint: 10.130.0.4:6379, mgr: 8 of 10 available, clientName: , IOCP: (Busy=0,Free=1400,Min=700,Max=1400), WORKER: (Busy=92,Free=1308,Min=700,Max=1400), Local-CPU: 0%, v: 2.0.601.3402 (Please take a look at this article for some common client-side issues that can cause timeouts: https://stackexchange.github.io/StackExchange.Redis/Timeouts)","Data":{"Redis-Message":"SET testcacheavailable","Redis-Timeout":"4000","Redis-Write-State":"Writing","Redis-Read-State":"DequeueResult","Redis-OutboundDeltaKB":"0KiB","Redis-InboundDeltaKB":"0KiB","Redis-Message-Current":"GET {key}","Redis-Message-Next":"GET {key}","Redis-OpsSinceLastHeartbeat":"0","Redis-Queue-Awaiting-Write":"16","Redis-Queue-Awaiting-Response":"68","Redis-Active-Writer":"True","Redis-Backlog-Writer":"Inactive","Redis-Inbound-Bytes":"0","Redis-Inbound-Pipe-Bytes":"1022427","Redis-Outbound-Pipe-Bytes":"0","Redis-Server-Endpoint":"10.130.0.4:6379","Redis-Manager":"8 of 10 available","Redis-Client-Name":"","Redis-ThreadPool-IO-Completion":"(Busy=0,Free=1400,Min=700,Max=1400)","Redis-ThreadPool-Workers":"(Busy=92,Free=1308,Min=700,Max=1400)","Redis-Busy-Workers":"92","Redis-Local-CPU":"0%","Redis-Version":"2.0.601.3402","redis-command":"SET testcacheavailable","request-sent-status":1,"redis-server":"10.130.0.4:6379"},"InnerException":null,"HelpURL":"https://stackexchange.github.io/StackExchange.Redis/Timeouts","StackTraceString":" at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor1 processor, ServerEndPoint server) in C:\projects\stackexchange-redis\src\StackExchange.Redis\ConnectionMultiplexer.cs:line 2258\r\n at StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor1 processor, ServerEndPoint server) in C:\\projects\\stackexchange-redis\\src\\StackExchange.Redis\\RedisBase.cs:line 54","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nExecuteSyncImpl\nStackExchange.Redis, Version=2.0.0.0, Culture=neutral, PublicKeyToken=c219ff1ca8c2ce46\nStackExchange.Redis.ConnectionMultiplexer\nT ExecuteSyncImpl[T](StackExchange.Redis.Message, StackExchange.Redis.ResultProcessor1[T], StackExchange.Redis.ServerEndPoint)","HResult":-2146233083,"Source":"StackExchange.Redis","WatsonBuckets":null,"commandStatus":1}`

beeyee0401 avatar Apr 28 '21 16:04 beeyee0401

There are many of these logs available. Since Redis never reconnected, it left our production environment unstable on this particular server. 12/13 servers were connected without issue, and the one particular server affected here did not get connected until we restarted the server.

bt-Knodel avatar May 03 '21 20:05 bt-Knodel

I have managed to get a lot of tests to fail with the same error message "Failed to nominate master", and have a general inkling that it is due to some kind of race condition or bug around when the PhysicalBridge ProcessBacklogAsync task starts, and starts actually processing messages added by QueueMessageOrFail, versus what other tasks are doing to put messages in that same queue, or perhaps versus when the heartbeat starts and starts processing timeouts.

TimLovellSmith avatar May 19 '21 15:05 TimLovellSmith

Update: we've fixed this and some other ugly cases in the 2.2.50 release. Please grab latest off NuGet and take it for a spin, and thanks to @TimLovellSmith for helping me track these down <3

NickCraver avatar Jun 23 '21 02:06 NickCraver