-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add exception catch for redis connection failure #1261
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1261 +/- ##
==========================================
+ Coverage 93.84% 95.01% +1.16%
==========================================
Files 22 43 +21
Lines 2341 5841 +3500
==========================================
+ Hits 2197 5550 +3353
- Misses 144 291 +147
Continue to review full report at Codecov.
|
rq/worker.py
Outdated
except redis.exceptions.ConnectionError as conn_err: | ||
self.log.error('Could not connect to Redis instance: %s ' | ||
'Retrying...', conn_err) | ||
time.sleep(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe would be better to use an exponential backoff approach here instead of trying each 1 second?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, added
self.log.error('Could not connect to Redis instance: %s ' | ||
'Retrying...', conn_err) | ||
time.sleep(connection_wait_time) | ||
connection_wait_time *= self.exponential_backoff_factor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's limit the connection_wait_time
to 60 seconds max. So it'll try every 1, 2, 4, 8 ... up to 60 seconds.
rq/worker.py
Outdated
@@ -567,14 +567,15 @@ def dequeue_job_and_maintain_ttl(self, timeout): | |||
self.set_state(WorkerStatus.IDLE) | |||
self.procline('Listening on ' + qnames) | |||
self.log.debug('*** Listening on %s...', green(qnames)) | |||
|
|||
connection_wait_time = 1.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the use of semicolons.
rq/worker.py
Outdated
time.sleep(connection_wait_time) | ||
connection_wait_time *= self.exponential_backoff_factor | ||
else: | ||
connection_wait_time = 1.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the use of semicolons.
rq/worker.py
Outdated
@@ -591,6 +592,13 @@ def dequeue_job_and_maintain_ttl(self, timeout): | |||
break | |||
except DequeueTimeout: | |||
pass | |||
except redis.exceptions.ConnectionError as conn_err: | |||
self.log.error('Could not connect to Redis instance: %s ' | |||
'Retrying...', conn_err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add Retrying in <wait_time> seconds...
rq/worker.py
Outdated
@@ -1,4 +1,4 @@ | |||
# -*- coding: utf-8 -*- | |||
#wait_time_after_connection_failure -*- coding: utf-8 -*- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this line need to be changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My mistake!
Hi @selwin rq workers are not automatically retrying to connect when connect is lost/redis-server is restarted for maintenance. So until rq worker is restarted, it keeps raising ConnectionError resulting in failure. Lately this is becoming serious issue in production. Hoping this PR can fix it. |
@Asrst because my comments haven't been addressed. |
@selwin Is there anything we can do since it is in this state from Jun 20 ? |
Yes, if my comments on this PR is addressed, this is also something I'd like to see merged in. |
I think I have resolved the issues now, please let me know if there is anything else! |
Resolves #1153
Resolves (Maybe?) #998