11

I'm porting a net 4 library to net-core 1.0.0-preview 2

It is using Stackexchange.Redis version 1.2.1 when developing my net-core library, and 1.2.0 for the net 4 version.

In net 4, my library has never failed when calling Redis commands.

In net-core, I get this error randomly:

 System.TimeoutException: Timeout performing GET netkey, inst: 6, queue: 10, qu: 0, qs: 10, qc: 0, wr: 0, wq: 0, in: 645, ar: 0, clientName: XXXXXX, serverEndpoint: Unspecified/XXXXXXX, keyHashSlot: XXXXX(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)
   at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor`1 processor, ServerEndPoint server)
   at StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor`1 processor, ServerEndPoint server)
   at StackExchange.Redis.RedisDatabase.StringGet(RedisKey key, CommandFlags flags)

UPDATE I'm using default configurations (connection timeout, connection retry, etc)

UPDATE Added keep-alive configuration but still failing

Any ideas?

2
  • does it work on a retry? Commented Mar 26, 2017 at 14:27
  • @BrokenGlass yes, the default value of "3" (times) Commented Mar 27, 2017 at 14:53

4 Answers 4

5

Updated SyncTimeout is not a good option because your redis command is runing very slow The reason of timeout is .net-core default threads count in threadpool is too low.

Just set maxThreads in environment variable.

ex:

ComPlus_ThreadPool_ForceMaxWorkerThreads 1000 ComPlus_ThreadPool_ForceMinWorkerThreads 50

Then run app in administrator identity(allow app read system environment variable)

It works to me

Sign up to request clarification or add additional context in comments.

1 Comment

I just added to docker ComPlus_ThreadPool_ForceMinWorkerThreads 100 and looks like it works. However, could you describe why this is so important? I am using a synchronous version of Add/Get etc from redis - but in an asynchronous method..
4

Solution: Updated SyncTimeout configuration to 10000. Tried with 5000 and failed, then with 10000 and fixed. Default value was 1000.

2 Comments

can you please let me where to put this configuration?
This should be part of your connection string to Redis, like "redis.cache.windows.net,password=y+v1,ssl=True,abortConnect=False,synctimeout=10000"
1

Have you tried upping the available threads? (Note, this is not from a .Net Core Project, so I'm not 100% certain the syntax is the same.)

I have the below in my Application_Start method in Global.asax.cs

private static int THREAD_MIN = 50; // 4 cores in production = 200
...                
//Per Redis docs, upping the number of threads available to handle the IO demands on the cloud.   
//https://github.com/StackExchange/StackExchange.Redis/blob/master/Docs/Timeouts.md 
ThreadPool.SetMinThreads(THREAD_MIN, THREAD_MIN);       

1 Comment

Sorry, it did not help. I cannot use this method in net core. Tried another solution that worked.
0

I use Microsoft.Extensions.Caching.Redis (2.1.2) in my ASP MVC .NET Core 2.1 project and had also same TimeoutException on calling the synchronous method GetString(key) from the service IDistributedCache. The solution is calling rather the asynchronous method:

var val = await distributedCache.GetStringAsync(key)

the issue is no longer occurring.

1 Comment

It still occurs here using await async

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.