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

Proposed by Chad Miller on 2010-04-27
Status: Merged
Approved by: Eric Casteleijn on 2010-04-28
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 on 2010-04-28
Tim Cole (community) 2010-04-27 Approve on 2010-04-27
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.
Tim Cole (tcole) wrote :

Sensible, I think.

review: Approve
Guillermo Gonzalez (verterok) wrote :

it's possible to add some tests for this?

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
1=== modified file 'desktopcouch/__init__.py'
2--- desktopcouch/__init__.py 2010-03-10 22:18:24 +0000
3+++ desktopcouch/__init__.py 2010-04-27 18:20:31 +0000
4@@ -68,13 +68,16 @@
5 #### ^^
6
7
8-def __find_port__linux(pid=None, ctx=local_files.DEFAULT_CONTEXT):
9+def __find_port__linux(pid=None, ctx=local_files.DEFAULT_CONTEXT,
10+ retries_left=3):
11 """This returns a valid port or raises a RuntimeError exception. It never
12 returns anything else."""
13 if pid is None:
14 pid = find_pid(start_if_not_running=True, ctx=ctx)
15
16 if pid is None:
17+ if retries_left:
18+ return __find_port__linux(pid, ctx, retries_left-1)
19 raise RuntimeError("Have no PID to use to look up port.")
20
21 proc_dir = "/proc/%d" % (pid,)
22@@ -92,6 +95,8 @@
23 (dirent_path,))
24 continue
25 except OSError:
26+ if retries_left:
27+ return __find_port__linux(pid, ctx, retries_left-1)
28 logging.exception("Unable to find file descriptors in %s" % proc_dir)
29 raise RuntimeError("Unable to find file descriptors in %s" % proc_dir)
30
31@@ -129,6 +134,8 @@
32 break
33
34 if port is None:
35+ if retries_left:
36+ return __find_port__linux(pid, ctx, retries_left-1)
37 raise RuntimeError("Unable to find listening port")
38
39 return port

Subscribers

People subscribed via source and target branches