Merge lp:~cmiller/desktopcouch/find-port-runtimeerror2 into lp:desktopcouch

Proposed by Chad Miller
Status: Merged
Approved by: Eric Casteleijn
Approved revision: 155
Merged at revision: 157
Proposed branch: lp:~cmiller/desktopcouch/find-port-runtimeerror2
Merge into: lp:desktopcouch
Diff against target: 39 lines (+8/-1)
1 file modified
desktopcouch/__init__.py (+8/-1)
To merge this branch: bzr merge lp:~cmiller/desktopcouch/find-port-runtimeerror2
Reviewer Review Type Date Requested Status
Eric Casteleijn (community) Approve
Tim Cole (community) Approve
Review via email: mp+24249@code.launchpad.net

Commit message

A possible fix for a bug I can't reproduce, Bug#465216. It is possible that two calls to find_port will happen near the same time. The steps tostarting up couchdb are 1) start couchdb if not already running, 2) get pid, 3) get port. Two processes can be in that chain at the same time, and only one will win the race of having started the winning couchdb. In that case, each should be willing to restart the entire chain over.

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

Sensible, I think.

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

it's possible to add some tests for this?

Revision history for this message
Eric Casteleijn (thisfred) wrote :

Looks good tests pass

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'desktopcouch/__init__.py'
--- desktopcouch/__init__.py 2010-03-10 22:18:24 +0000
+++ desktopcouch/__init__.py 2010-04-27 18:20:31 +0000
@@ -68,13 +68,16 @@
68#### ^^68#### ^^
6969
7070
71def __find_port__linux(pid=None, ctx=local_files.DEFAULT_CONTEXT):71def __find_port__linux(pid=None, ctx=local_files.DEFAULT_CONTEXT,
72 retries_left=3):
72 """This returns a valid port or raises a RuntimeError exception. It never73 """This returns a valid port or raises a RuntimeError exception. It never
73 returns anything else."""74 returns anything else."""
74 if pid is None:75 if pid is None:
75 pid = find_pid(start_if_not_running=True, ctx=ctx)76 pid = find_pid(start_if_not_running=True, ctx=ctx)
7677
77 if pid is None:78 if pid is None:
79 if retries_left:
80 return __find_port__linux(pid, ctx, retries_left-1)
78 raise RuntimeError("Have no PID to use to look up port.")81 raise RuntimeError("Have no PID to use to look up port.")
7982
80 proc_dir = "/proc/%d" % (pid,)83 proc_dir = "/proc/%d" % (pid,)
@@ -92,6 +95,8 @@
92 (dirent_path,))95 (dirent_path,))
93 continue96 continue
94 except OSError:97 except OSError:
98 if retries_left:
99 return __find_port__linux(pid, ctx, retries_left-1)
95 logging.exception("Unable to find file descriptors in %s" % proc_dir)100 logging.exception("Unable to find file descriptors in %s" % proc_dir)
96 raise RuntimeError("Unable to find file descriptors in %s" % proc_dir)101 raise RuntimeError("Unable to find file descriptors in %s" % proc_dir)
97102
@@ -129,6 +134,8 @@
129 break134 break
130135
131 if port is None:136 if port is None:
137 if retries_left:
138 return __find_port__linux(pid, ctx, retries_left-1)
132 raise RuntimeError("Unable to find listening port")139 raise RuntimeError("Unable to find listening port")
133140
134 return port141 return port

Subscribers

People subscribed via source and target branches