diff options
author | Andy McCurdy <andy@andymccurdy.com> | 2019-07-28 13:36:05 -0700 |
---|---|---|
committer | Andy McCurdy <andy@andymccurdy.com> | 2019-07-28 13:36:05 -0700 |
commit | 9e4c1fffe6466d6246e5d2f15e49759f73880d18 (patch) | |
tree | e7841421807f0243e87915a97a1012264f921d22 /redis/client.py | |
parent | 6ce11f130d3bd7106e4879db70d77c5708d2898e (diff) | |
download | redis-py-9e4c1fffe6466d6246e5d2f15e49759f73880d18.tar.gz |
Pipelines shouldn't retry ConnectionErrors implicitly
Diffstat (limited to 'redis/client.py')
-rwxr-xr-x | redis/client.py | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/redis/client.py b/redis/client.py index fb1297a..c13ccff 100755 --- a/redis/client.py +++ b/redis/client.py @@ -3499,16 +3499,26 @@ class Pipeline(Redis): return self.parse_response(conn, command_name, **options) except (ConnectionError, TimeoutError) as e: conn.disconnect() - if not conn.retry_on_timeout and isinstance(e, TimeoutError): + # if we were already watching a variable, the watch is no longer + # valid since this connection has died. raise a WatchError, which + # indicates the user should retry this transaction. + if self.watching: + self.reset() + raise WatchError("A ConnectionError occured on while watching " + "one or more keys") + # if retry_on_timeout is not set, or the error is not + # a TimeoutError, raise it + if not (conn.retry_on_timeout and isinstance(e, TimeoutError)): + self.reset() raise - # if we're not already watching, we can safely retry the command + + # retry_on_timeout is set, this is a TimeoutError and we are not + # already WATCHing any variables. retry the command. try: - if not self.watching: - conn.send_command(*args) - return self.parse_response(conn, command_name, **options) - except ConnectionError: - # the retry failed so cleanup. - conn.disconnect() + conn.send_command(*args) + return self.parse_response(conn, command_name, **options) + except (ConnectionError, TimeoutError): + # a subsequent failure should simply be raised self.reset() raise @@ -3667,18 +3677,17 @@ class Pipeline(Redis): return execute(conn, stack, raise_on_error) except (ConnectionError, TimeoutError) as e: conn.disconnect() - if not conn.retry_on_timeout and isinstance(e, TimeoutError): - raise # if we were watching a variable, the watch is no longer valid # since this connection has died. raise a WatchError, which - # indicates the user should retry his transaction. If this is more - # than a temporary failure, the WATCH that the user next issues - # will fail, propegating the real ConnectionError + # indicates the user should retry this transaction. if self.watching: raise WatchError("A ConnectionError occured on while watching " "one or more keys") - # otherwise, it's safe to retry since the transaction isn't - # predicated on any state + # if retry_on_timeout is not set, or the error is not + # a TimeoutError, raise it + if not (conn.retry_on_timeout and isinstance(e, TimeoutError)): + raise + # retry a TimeoutError when retry_on_timeout is set return execute(conn, stack, raise_on_error) finally: self.reset() |