ServiceStack.Redis: Unable to Connect: sPort: 0

ghz 1years ago ⋅ 10023 views

Question

Sometimes (not always) I am getting

"Unable to Connect: sPort: 0"

error when trying to get value from Redis when using ServiceStack.Redis. Does anyone know what that might mean? I am using PooledRedisClientManager to get the client.


Answer

I believe you can fix this by increasing the pool's ConnectTimeout. I had it set very low (10ms), so when the pool was created, some of the clients were unable to connect in that short period. If the pool returned one of these clients, it would throw this error (the "0" port is because it's not connected -- it doesn't know what port it's not connected to). After a delay, all of the clients are able to connect.

I increased my connect timeout to 500ms, and the problem went away -- the clients all connect, though some of them block for a couple hundred milliseconds. But that's much better than an error.