ctstone / csredis

.NET client for Redis and Redis Sentinel (2.8). Includes both synchronous and asynchronous clients.
Other
292 stars 111 forks source link

socket error #24

Open ofirgeller opened 10 years ago

ofirgeller commented 10 years ago

any idea what is the reason for this?

i am creating a new csRedis client for every request. is this a bad practice? i know clients like SE.redis reuse the connection. but the examples on this repo show the using statement so that is what i did.

System.Net.Sockets.SocketException (0x80004005): Only one usage of each socket address (protocol/network address/port) is normally permitted 191.234.53.96:6379 at System.Net.Sockets.Socket.Connect(IPAddress[] addresses, Int32 port) at System.Net.Sockets.Socket.Connect(String host, Int32 port) at System.Net.Sockets.Socket.Connect(EndPoint remoteEP) at CSRedis.Internal.RedisConnector.Connect() at CSRedis.Internal.RedisConnector.Call[T](RedisCommand1 command) at CSRedis.RedisClient.Write[T](RedisCommand1 command) at Common.Cache.csRedis.AddStringToCache(String key, String value, Nullable`1 minutes)

ctstone commented 10 years ago

CSRedis does not (yet) use connection pooling, so it sounds like you are exhausting your ephemeral port range with many closed connections hanging around in the TIME_WAIT state, which according to this old blog post is 240 seconds.

For now, you can try reusing a shared (static) csredis instance with the Async methods and Reconnect enabled. Meanwhile I'll investigate connection pooling.

ofirgeller commented 10 years ago

I will try that, any thing to be careful of?