Redis timeouts when used for session storage

Was seeing a lot of timeout errors in our apps in Azure through app insights. A lot meaning more than 50 per hour. Not to mention sporadic down time. All the timeouts were trying to talk to our redis caches that we use as simple session storage.

Timeout performing EVAL, inst: 1, mgr: Inactive, err: never, queue: 8, qu: 0, qs: 8, qc: 0, wr: 0, wq: 0, in: 43403, ar: 0,
clientName: ServerName1234, serverEndpoint: Unspecified/CacheName.redis.cache.windows.net:6380, keyHashSlot: 12345, IOCP: (Busy=0,Free=1000,Min=4,Max=1000), WORKER: (Busy=6,Free=8185,Min=4,Max=8191), Local-CPU: unavailable
(Please take a look at this article for some common client-side issues that can cause timeouts: https://github.com/StackExchange/StackExchange.Redis/tree/master/Docs/Timeouts.md)

I took a look at that article which lead to more articles. These 3 to be specific.

https://docs.microsoft.com/en-us/azure/redis-cache/cache-aspnet-session-state-provider
https://gist.github.com/JonCole/925630df72be1351b21440625ff2671f#file-redis-bestpractices-general-md
https://azure.microsoft.com/en-in/blog/investigating-timeout-exceptions-in-stackexchange-redis-for-azure-redis-cache/

After perusing those I found I needed to add some connection timeout settings to the connection string. Probably obvious to some, but my extent of redis knowledge was knowing we used it and clicking some buttons in the portal to build caches for our environments. This is what I ended up adding to the connection string in the web.config.


connectionTimeoutInMilliseconds = "15000" 
operationTimeoutInMilliseconds = "1000"
retryTimeoutInMilliseconds="3000"

That resolved the timeouts and performance and availability went back to normal.

Here is an example of the full connection string for session storage for context.


<! Example connection string -->    
<sessionState timeout="1440" mode="Custom" customProvider="MySessionStateStore">
      <providers>
        <add name="MySessionStateStore"
        applicationName="Meh"
        type="Microsoft.Web.Redis.RedisSessionStateProvider"
        host="RedisCacheName.redis.cache.windows.net"
        port="6380"
        ssl="true"
        accessKey="************************"
        connectionTimeoutInMilliseconds = "15000"
        operationTimeoutInMilliseconds = "1000"
        retryTimeoutInMilliseconds="3000"
        />
      </providers>
    </sessionState>

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.