Merge lp:~cmiller/desktopcouch/sleep-and-retry-on-socket-error into lp:desktopcouch

Proposed by Chad Miller
Status: Merged
Approved by: Rodrigo Moya
Approved revision: 155
Merged at revision: 158
Proposed branch: lp:~cmiller/desktopcouch/sleep-and-retry-on-socket-error
Merge into: lp:desktopcouch
Diff against target: 28 lines (+7/-0)
1 file modified
desktopcouch/records/server_base.py (+7/-0)
To merge this branch: bzr merge lp:~cmiller/desktopcouch/sleep-and-retry-on-socket-error
Reviewer Review Type Date Requested Status
Rodrigo Moya (community) Approve
Guillermo Gonzalez Needs Information
Tim Cole (community) Approve
Review via email: mp+24245@code.launchpad.net

Commit message

Try to avoid a bug I can not reproduce, which may be related to suspend in some way. On a socket error when trying to talk to couchdb, reconnect, which may spawn a new couchdb if one is not running (for reasons that are unknown to Chad). (LP: #522538)

To post a comment you must log in.
Revision history for this message
Tim Cole (tcole) wrote :

Some sort of backoff on retry would be good, particularly if we're not only connecting to localhost with this code (in which case e.g. there may be actual network issues).

review: Approve
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

+1 on Tim's idea about a backoff

review: Approve
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

btw, could you add some test for this case?
As I don't know much about desktopcouch code, I don't know if it's even possible...but I think it would be good to have a test for this.

review: Needs Information
Revision history for this message
Rodrigo Moya (rodrigo-moya) wrote :

Yeah, it should have some kind of max number of reconnect attempts

review: Needs Fixing
Revision history for this message
Chad Miller (cmiller) wrote :

Rodrigo, it does have a maximum. This is the error condition in the body of a 'for' loop.

Revision history for this message
Rodrigo Moya (rodrigo-moya) wrote :

> Rodrigo, it does have a maximum. This is the error condition in the body of a
> 'for' loop.

ah, sorry, missed that, so approving

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/records/server_base.py'
2--- desktopcouch/records/server_base.py 2010-04-19 16:07:11 +0000
3+++ desktopcouch/records/server_base.py 2010-04-27 17:32:29 +0000
4@@ -23,6 +23,7 @@
5
6 import httplib2, urlparse, cgi, copy
7 from time import time
8+import socket
9
10 # please keep desktopcouch python 2.5 compatible for now
11
12@@ -167,10 +168,16 @@
13 logging.warn("DB connection timed out. Reconnecting.")
14 self._reconnect()
15 continue
16+ elif isinstance(e, socket.error):
17+ logging.warn("Other socket error %s. Reconnecting.", e)
18+ time.sleep(0.3)
19+ self._reconnect()
20+ continue
21 else:
22 raise
23
24 def _reconnect(self):
25+ logging.info("Connecting to %s." % (self.server_uri or "discovered local port",))
26 self._server = self._server_class(self.server_uri,
27 **self._server_class_extras)
28 if self._database_name not in self._server:

Subscribers

People subscribed via source and target branches