Looking for guidance on handling temporary network issues when using the StackExchange.Redis client.
For clarification, I do not mean initially connecting to the Redis server with ConnectionMultiplexer.Connect(). I am referring to how to handle connections that are interrupted for whatever reason in the middle of an operation. (we can assume that the command is idempotent, StringSet, StringGet)
I ask because we are migrating from the ServiceStack to the StackExchange client. In the code we are replacing, which uses ServiceStack, exceptions were caught and the operation would be attempted again after a short thread.sleep(). This happens fairly frequently in our production environment and on most occasions the retry would work.
Usually it's a System.Net.SocketException with the message "An established connection was aborted by the software in your host machine" or "An existing connection was forcibly closed by the remote host"
If a System.Net.SocketException is thrown, does StackExchange.Redis automatically retry up until the syncTimeout time has elapsed?
If SE.Redis does not automatically retry, are there any suggested steps that should happen between an initial operation failure and a retry in our code? Such as:
- waiting a short amount of time?
- recreating the multiplexer? (I'd guess not)
- calling Close() and Configure()?
Thank you for any guidance.
It doesn't retry automatically. If an error occurs, you need to catch and retry yourself.
In terms of the actual retry, as long as some of the multiplexer's connections are still alive, you can just back off and try again.
If a connection fails, it tries to recover, but there's a long standing bug where it can intermittently get into some unrecoverable state and remain disconnected. We work around this by re-creating the multiplexer if IsConnected
ever returns false
.
来源:https://stackoverflow.com/questions/45446394/handling-of-transient-network-errors-with-stackexchange-redis