I continued to debug this issue and fixed many things on my platform to avoid this exception. Here is what I did to solve the problem:
Summary:
People encountering this exception should check:
- That the PooledRedisClientsManager (IRedisClientsManager) is registered in the Singleton area
- What RedisMqServer (IMessageService) is registered in Singleton scope
- So that the RedisClient utility returned from any of the above is correctly removed to ensure that the merged clients are not out of date.
The solution to my problem:
First of all, this exception is thrown by the PooledRedisClient pool because it has no more empty connections available .
I register all the necessary Redis elements in the StructureMap IoC container (not a unity, as in the case of the author). Thanks to this post, I was reminded that the PooledRedisClientManager should be a single - I also decided to register RedisMqServer as a singleton:
ObjectFactory.Configure(x => {
My "BuildRedisClientManager" function looks like this:
private static IRedisClientsManager BuildRedisClientsManager() { var appSettings = new AppSettings(); var redisClients = appSettings.Get("redis-servers", "redis.local:6379").Split(','); var redisFactory = new PooledRedisClientManager(redisClients); redisFactory.ConnectTimeout = 5; redisFactory.IdleTimeOutSecs = 30; redisFactory.PoolTimeout = 3; return redisFactory; }
Then, when it comes to creating messages, it is very important that the disposed RedisClient is properly disposed of, otherwise we will encounter the terrible โTimeout expiredโ (thanks to this message ). I have the following helper code to send a message to a queue:
public static void PublishMessage<T>(T msg) { try { using (var producer = GetMessageProducer()) { producer.Publish<T>(msg); } } catch (Exception ex) {
I hope this also helps solve your problem.
nover
source share