StackExchange.Redis RedisTimeoutException in a .NET app
StackExchange.Redis.RedisTimeoutExceptionShort answer
A RedisTimeoutException means a command did not finish in time. The message itself shows why: qs, in, and the IOCP and WORKER thread counts. Busy above Min points to thread pool starvation, a growing qs to a large value ahead of the queue, and slow commands or a failover point at the server.
Fix it fast
1Find out which cause you have
Copy the full exception message and read three things: qs (sent, awaiting reply), in (bytes not yet read), and Busy against Min in the IOCP and WORKER pools.
redis-cli --bigkeys2Match what you see, then jump to its fix
- 1
Busy is greater than Min in the IOCP or WORKER part of the messageThread pool starvation on the clientFix - 2
qs keeps growing, or SLOWLOG shows commands such as KEYS or large MGETA large value or a slow command blocks the queueFix - 3
Timeouts line up with CPU spikes, or a high in: value (bytes waiting to be read)The client host or the cache is out of CPU, memory or bandwidthFix - 4
A short burst of timeouts, then everything recovers; the Errors metric shows a Failover countA failover or patch on Azure Cache for RedisFix
- 1
What does the error look like?
StackExchange.Redis.RedisTimeoutExceptionTimeout performing GET MyKey (1000ms), inst: 2, qs: 6, in: 0IOCP: (Busy=6,Free=994,Min=4,Max=1000), WORKER: (Busy=3,Free=997,Min=4,Max=1000)
Cause 1 of 4
Thread pool starvation on the client
1Check
When the pool has to grow during a burst, data the server already sent waits to be read. The documentation says the most common reason is blocking on async calls, and raising the minimum does not fix that.
grep -R -n -E "\.Result|\.Wait\(\)|GetAwaiter\(\)\.GetResult" --include=*.cs .2Fix
First remove sync-over-async calls. If threads are still short during bursts, raise the minimum thread counts, starting around 200 to 300 and then tuning.
ThreadPool.SetMinThreads(200, 200);3Verify
Re-run the load that timed out and read the Busy and Min values in any new message.
dotnet run -c ReleaseConfirmed by raw.githubusercontent.com
Cause 2 of 4
A large value or a slow command blocks the queue
1Check
One TCP connection reads one response at a time, so a big response holds up the small ones behind it. Redis runs commands on one thread, so a slow command blocks the rest.
redis-cli --bigkeys
redis-cli SLOWLOG GET 102Fix
Split large values into smaller ones, replace KEYS with SCAN, and use a pool of ConnectionMultiplexer objects if one connection is saturated.
redis-cli SLOWLOG GET 103Verify
SLOWLOG should no longer list the slow commands, and qs should stay low.
redis-cli SLOWLOG GET 10Confirmed by learn.microsoft.com
Cause 3 of 4
The client host or the cache is out of CPU, memory or bandwidth
1Check
Keep client CPU under 80 percent. Check system-wide CPU and memory on the client and the server load metric of the cache.
redis-cli INFO cpu2Fix
Move the client to a larger VM, reduce the data sent per request, or scale the cache up or out.
redis-cli INFO memory3Verify
Watch server load and client CPU during the same traffic.
redis-cli INFO cpuConfirmed by learn.microsoft.com
Cause 4 of 4
A failover or patch on Azure Cache for Redis
1Check
During a failover, an operation that was sent but not answered can time out. New requests on the closed connection fail until it reconnects.
echo Check Azure portal: cache > Metrics > Errors, split by ErrorType2Fix
Restart the client applications so all connections are recreated and redistributed between the nodes.
# restart each client app after the failover, for example:
sudo systemctl restart my-app3Verify
Compare timeout times with the Failover count.
echo Same time window in the Errors chartConfirmed by learn.microsoft.com
How do I stop it coming back?
- Never block on async Redis calls with .Result or .Wait().
- Keep values small and avoid KEYS in production.
- Alert on server load and client CPU.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- RaheebA consumer app shipped to both stores from one Flutter codebase on a .NET and Azure back end.
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Loade DriverThe driver side of a delivery platform: live jobs, routing and earnings, past 5K Google Play downloads.
Related fixes
Databases
Azure Database for MySQL refuses a connection that does not use SSL
ERROR 3159 (HY000): Connections using insecure transport are prohibited while --require_secure_transport=ON.
Azure Database for MySQL Flexible Server requires encrypted connections by default (require_secure_transport = ON, TLS 1.2).
4 causes, each with a fixDatabases
Dapper cannot find a constructor that fits the query columns
The error appears when Dapper maps rows into a record or a class whose only constructor takes arguments
Dapper looks for a public parameterless constructor first.
3 causes, each with a fixDatabases
.NET Framework app cannot load the Unsafe assembly after a NuGet update
System.IO.FileLoadException
This happens on .NET Framework when one package asks for a different version of the assembly than the one in your bin folder, and no binding redirect joins them.
4 causes, each with a fixDatabases
EF Core logs 'An error occurred using the connection to database' with MySQL
Can't connect to MySQL server on 'host_name' (111)
This EF Core message is only a wrapper.
3 causes, each with a fixDatabases
DbContextOptionsBuilder has no UseMySql method
Cannot find the UseMysql method on DbContextOptions
UseMySql comes from a provider package, not from EF Core itself.
3 causes, each with a fixDatabases
Jedis cannot borrow a connection from its pool
Caused by: java.net.SocketTimeoutException
The pool could not give the code a working connection in time.
3 causes, each with a fix