Merge lp:~mandel/desktopcouch/port-cannot-be-read-slow into lp:desktopcouch

Proposed by Manuel de la Peña
Status: Merged
Approved by: Eric Casteleijn
Approved revision: 105
Merged at revision: not available
Proposed branch: lp:~mandel/desktopcouch/port-cannot-be-read-slow
Merge into: lp:desktopcouch
Diff against target: 62 lines (+16/-7)
1 file modified
desktopcouch/start_local_couchdb.py (+16/-7)
To merge this branch: bzr merge lp:~mandel/desktopcouch/port-cannot-be-read-slow
Reviewer Review Type Date Requested Status
Eric Casteleijn (community) Approve
Chad Miller (community) Approve
Review via email: mp+15100@code.launchpad.net

Commit message

For start-up, loop over finding the port in case the port is not available when the PID is.

In pid-finding and port-finding loops, loop for exponentially longer times instead of many short periods, and quit totally after ~7 seconds for each.

To post a comment you must log in.
105. By Manuel de la Peña

Fixed small error with print statement and misplacement of timeout.

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

Great!

Mandel has signed the contributor agreement.

review: Approve
Revision history for this message
Eric Casteleijn (thisfred) wrote :
Download full text (15.9 KiB)

Thanks Manuel! Code looks good, but the first time I ran the tests, I got the traceback below, which is strange. Is this (meaning the memory dump) what normally happens when the 5th try still times out?

eric@thelog:~/canonical/desktopcouch/r-mandel$ PYTHONPATH=. trial desktopcouch
ini file is at /tmp/tmp5oQgGD/config/desktop-couchdb.ini
Apache CouchDB has started, time to relax.
...waiting for couchdb to start...
...waiting for couchdb to start...
...waiting for couchdb to start...
2009-11-20 15:53:22,169 - Unable to find listening port
2009-11-20 15:53:22,199 - Looked at the following processes for inode :
2009-11-20 15:53:22,202 - sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
   0: 00000000:3E81 00000000:0000 0A 00000000:00000000 00:00000000 00000000 1000 0 10340 1 f5c96600 300 0 0 2 -1
   1: 0100007F:19C8 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 9567 1 f5c97440 300 0 0 2 -1
   2: 00000000:1628 00000000:0000 0A 00000000:00000000 00:00000000 00000000 123 0 9056 1 f6052ac0 300 0 0 2 -1
   3: 00000000:1269 00000000:0000 0A 00000000:00000000 00:00000000 00000000 1000 0 10334 1 f5c96f80 300 0 0 2 -1
   4: 0100007F:B1CE 00000000:0000 0A 00000000:00000000 00:00000000 00000000 1000 0 14230 1 f5c97900 300 0 0 2 -1
   5: 00000000:0050 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 8359 1 f6050e40 300 0 0 2 -1
   6: 00000000:1111 00000000:0000 0A 00000000:00000000 00:00000000 00000000 123 0 8497 1 f5c96ac0 300 0 0 2 -1
   7: 00000000:94F3 00000000:0000 0A 00000000:00000000 00:00000000 00000000 1000 0 285292 1 ddc63900 300 0 0 2 -1
   8: 00000000:9854 00000000:0000 0A 00000000:00000000 00:00000000 00000000 123 0 8596 1 f6051300 300 0 0 2 -1
   9: 0501A8C0:0035 00000000:0000 0A 00000000:00000000 00:00000000 00000000 131 0 6009 1 f5c957c0 300 0 0 2 -1
  10: 0100007F:0035 00000000:0000 0A 00000000:00000000 00:00000000 00000000 131 0 5237 1 f5c94000 300 0 0 2 -1
  11: 00000000:0016 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 5659 1 f5c94980 300 0 0 2 -1
  12: 0100007F:0277 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 22448 1 f3169c80 300 0 0 2 -1
  13: 0100007F:1538 00000000:0000 0A 00000000:00000000 00:00000000 00000000 122 0 6790 1 f5c94e40 300 0 0 2 -1
  14: 0100007F:03B9 00000000:0000 0A 00000000:00000000 00:00000000 00000000 131 0 5251 1 f5c944c0 300 0 0 2 -1
  15: 0100007F:01BB 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 8358 1 f6050980 300 0 0 2 -1
  16: 0...

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

Ok, the memory dump was not caused by this branch. And the timeout was exactly as it should be, so approving. Thanks again!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/start_local_couchdb.py'
2--- desktopcouch/start_local_couchdb.py 2009-11-18 18:43:41 +0000
3+++ desktopcouch/start_local_couchdb.py 2009-11-20 20:38:09 +0000
4@@ -220,14 +220,24 @@
5 exit(1)
6
7 # give the process a chance to start
8- for timeout in xrange(1000):
9+ for timeout in (0.1, 0.1, 0.2, 0.5, 1, 3, 5):
10 pid = read_pidfile(ctx=ctx)
11- time.sleep(0.3)
12 if pid is not None and process_is_couchdb(pid):
13 break
14 print "...waiting for couchdb to start..."
15+ time.sleep(timeout)
16+
17+ # loop for a number of times until the port has been found, this
18+ # has to be done to prevent a race condition when trying to retrieve
19+ # the port number is slow hardware (ie netbooks)
20+ for timeout in (0.1, 0.1, 0.2, 0.5, 1, 3, 5):
21+ port = desktopcouch.find_port(pid=pid)
22+ if port is not None: break
23+ print "...waiting for couchdb to start..."
24+ time.sleep(timeout)
25+
26 ctx.ensure_files_not_readable()
27- return pid
28+ return pid, port
29
30 def update_design_documents(ctx=local_files.DEFAULT_CONTEXT):
31 """Check system design documents and update any that need updating
32@@ -274,7 +284,7 @@
33 # than inefficiently just overwriting it regardless
34 db.add_view(view_name, mapjs, reducejs, dd_name)
35
36-def write_bookmark_file(username, password, pid, ctx=local_files.DEFAULT_CONTEXT):
37+def write_bookmark_file(username, password, port, ctx=local_files.DEFAULT_CONTEXT):
38 """Write out an HTML document that the user can bookmark to find their DB"""
39 bookmark_file = os.path.join(ctx.db_dir, "couchdb.html")
40
41@@ -293,7 +303,6 @@
42 html = fp.read()
43 fp.close()
44
45- port = desktopcouch.find_port(pid=pid)
46 fp = open(bookmark_file, "w")
47 try:
48 if port is None:
49@@ -311,13 +320,13 @@
50 def start_couchdb(ctx=local_files.DEFAULT_CONTEXT):
51 """Execute each step to start a desktop CouchDB."""
52 username, password = create_ini_file(ctx=ctx)
53- pid = run_couchdb(ctx=ctx)
54+ pid, port = run_couchdb(ctx=ctx)
55 # Note that we do not call update_design_documents here. This is because
56 # Couch won't actually have started yet, so when update_design_documents
57 # calls the Records API, that will call back into get_port and we end up
58 # starting Couch again. Instead, get_port calls update_design_documents
59 # *after* Couch startup has occurred.
60- write_bookmark_file(username, password, pid, ctx=ctx)
61+ write_bookmark_file(username, password, port, ctx=ctx)
62 return pid
63
64

Subscribers

People subscribed via source and target branches