Handling of transient network errors with StackExchange.Redis

核能气质少年 提交于 2019-12-08 02:43:33

问题


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.


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!