Managed Redis fails with StackExchange.Redis.RedisConnectionException after a few days of usage and does not return to e healthy state

Sven Carstensen 0 Reputation points
2025-06-10T06:46:26.74+00:00

We are using Azure Managed Redis, running in Balanced B0, size 0.5GB, location West Europe.

After a few days our Container Apps (.NET 9) cannot connect anymore and get the following two exceptions:

The message timed out in the backlog attempting to send because no connection became available (5000ms) - Last Connection Exception: UnableToConnect (0-sent) on XYZ.westeurope.redis.azure.net:10000/Interactive, Flushed/ReadAsync, last: ECHO, origin: ResetNonConnected, outstanding: 13, last-read: 5s ago, last-write: 4s ago, unanswered-write: 4s ago, keep-alive: 60s, state: ConnectedEstablishing, mgr: 10 of 10 available, last-heartbeat: never, global: 5s ago, v: 2.8.24.3255, command=HGET, timeout: 5000, inst: 0, qu: 2, qs: 0, aw: False, bw: CheckingForTimeout, rs: ReadAsync, ws: Idle, in: 0, last-in: 0, cur-in: 0, sync-ops: 0, async-ops: 9, serverEndpoint: XYZ.westeurope.redis.azure.net:10000, conn-sec: 22.99, aoc: 0, mc: 1/1/0, mgr: 10 of 10 available, clientName: abc (SE.Redis-v2.8.24.3255), IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=0,Free=32767,Min=1,Max=32767), POOL: (Threads=7,QueuedItems=0,CompletedItems=441,Timers=19), v: 2.8.24.3255

The message timed out in the backlog attempting to send because no connection became available (5000ms) - Last Connection Exception: It was not possible to connect to the redis server(s). There was an authentication failure; check that passwords (or client certificates) are configured correctly: (RedisServerException) Error: WRONGPASS invalid username-password pair ConnectTimeout, command=HMSET, timeout: 5000, inst: 0, qu: 1, qs: 0, aw: False, bw: CheckingForTimeout, rs: ReadAsync, ws: Idle, in: 0, last-in: 0, cur-in: 0, sync-ops: 9, async-ops: 568, serverEndpoint: XYZ.westeurope.redis.azure.net:10000, conn-sec: 16.79, aoc: 0, mc: 1/1/0, mgr: 10 of 10 available, clientName: ABC (SE.Redis-v2.8.24.3255), PerfCounterHelperkeyHashSlot: 10240, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=77,Free=32690,Min=1,Max=32767), POOL: (Threads=106,QueuedItems=1,CompletedItems=2321851,Timers=27), v: 2.8.24.3255

We use a user managed identity to connect. That identity can connect to other services like Azure table. So, the identity is existing and valid.

The only way we could get Redis working again was by deleting and recreating the Redis resource.

Monitoring is not showing any problems: 2MB used. Server load 30 to 60% - which is interesting because our apps can't connect. Connected Clients and Total Operations show both 10 with Count aggregation.

Any idea what could cause this?

Azure Cache for Redis
Azure Cache for Redis
An Azure service that provides access to a secure, dedicated Redis cache, managed by Microsoft.
305 questions
{count} votes

1 answer

Sort by: Most helpful
  1. PratikLad 1,825 Reputation points Microsoft External Staff Moderator
    2025-06-19T16:49:16.7933333+00:00

    Hi Sven Carstensen,

    You can refer to the official Document on Cache management FAQs - Azure Cache for Redis | Microsoft Learn for detailed information.

    The timeout exception and the following connection error from StackExchange.Redis indicate potential client-side performance bottlenecks, particularly related to .NET ThreadPool usage:

    
    RedisServerException) Error: WRONGPASS invalid username-password pair ConnectTimeout, command=HMSET, timeout: 5000, inst: 0, qu: 1, qs: 0, aw: False, bw: CheckingForTimeout, rs: ReadAsync, ws: Idle, in: 0, last-in: 0, cur-in: 0, sync-ops: 9, async-ops: 568, serverEndpoint: XYZ.westeurope.redis.azure.net:10000, conn-sec: 16.79, aoc: 0, mc: 1/1/0, mgr: 10 of 10 available, clientName: ABC (SE.Redis-v2.8.24.3255), PerfCounterHelperkeyHashSlot: 10240, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (**Busy=77**,Free=32690,Min=1,Max=32767), POOL: (Threads=106,QueuedItems=1,CompletedItems=2321851,Timers=27), v: 2.8.24.3255
    
    

    This log shows that 77 worker threads were busy at the time of the failure, while the ThreadPool’s minimum thread count was just 1.

    When the number of busy threads exceeds the minimum, the .NET ThreadPool throttles thread creation, which can delay Redis operations and lead to TimeoutException errors. You can read more about this behavior in:

    Increase the minimum thread count early in your app's lifecycle. Add this line of code as early as possible (e.g., in Program.cs, Application_Start(), or the main method):

    
    System.Threading.ThreadPool.SetMinThreads(200, 200);
    
    
    • This is not per-core: the values apply globally.
    • Start with 200 and monitor; if the busy thread count still exceeds that, increase accordingly.

    Monitor CPU and memory usage of the container or VM. If your Redis client is under heavy CPU/memory load, this can exacerbate timeouts.

    Scale your application appropriately:

    While these client-side performance improvements are crucial, please note that the "WRONGPASS" error also indicates a possible authentication issue (e.g., with Managed Identity or token expiration). If you're using Azure Managed Identity, ensure token handling and Redis connection setup are configured correctly.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.