CouchDatabase() call hangs

Bug #682866 reported by Michael Terry
18
This bug affects 2 people
Affects Status Importance Assigned to Milestone
couchdb (Ubuntu)
Fix Released
High
Chris Coulson
Natty
Fix Released
High
Chris Coulson

Bug Description

Binary package hint: desktopcouch

I have a simple program that calls CouchDatabase("test_project", create=True) and doesn't return. This may not be the right component, please move as you see fit.

My program spat out the following, which is not usual:

"""
Removing stale, deceptive pid file.
Apache CouchDB has started, time to relax.
Browse your desktop CouchDB at file:///home/mike/.local/share/desktop-couch/couchdb.html
"""

The stacktrace after pressing Ctrl-C is pasted below. It seems a little garbled, like all three threads printed to terminal at same time.

"""
Traceback (most recent call last):
Traceback (most recent call last):
  File "./test-project", line 60, in <module>
Traceback (most recent call last):
  File "/home/mike/Code/quickly/quickly-11.03.0/data/templates/ubuntu-application/create.py", line 113, in <module>
  File "/home/mike/Code/quickly/quickly-11.03.0/bin/quickly", line 101, in <module>
    preferences.db_connect()
        subprocess.call(['./' + project_name], cwd='bin/')
  File "/tmp/test-project/test_project/preferences.py", line 53, in db_connect
exit(main())
  File "/usr/lib/python2.6/subprocess.py", line 470, in call
  File "/home/mike/Code/quickly/quickly-11.03.0/bin/quickly", line 86, in main
    self._database = CouchDatabase(self._db_name, create=True)
  File "/usr/lib/python2.6/dist-packages/desktopcouch/records/server.py", line 56, in __init__
    return(command.launch(os.getcwd(), command_args, opt_template))
  File "/home/mike/Code/quickly/quickly-11.03.0/quickly/commands.py", line 510, in launch
    server_class=server_class, oauth_tokens=oauth_tokens, ctx=ctx)
  File "/usr/lib/python2.6/dist-packages/desktopcouch/records/server_base.py", line 155, in __init__
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.6/subprocess.py", line 1182, in wait
        self._reconnect()
[self.command] + command_args, cwd=project_path)
  File "/usr/lib/python2.6/subprocess.py", line 470, in call
  File "/usr/lib/python2.6/dist-packages/desktopcouch/records/server.py", line 60, in _reconnect
    port = desktopcouch.find_port(ctx=self.ctx)
  File "/usr/lib/python2.6/dist-packages/desktopcouch/__init__.py", line 106, in find_port
    pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
  File "/usr/lib/python2.6/subprocess.py", line 455, in _eintr_retry_call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.6/subprocess.py", line 1182, in wait
    return func(*args)
    return _direct_access_find_port(pid=pid, ctx=ctx)
KeyboardInterrupt File "/usr/lib/python2.6/dist-packages/desktopcouch/__init__.py", line 131, in __find_port__linux

    pid = find_pid(start_if_not_running=True, ctx=ctx)
  File "/usr/lib/python2.6/dist-packages/desktopcouch/__init__.py", line 93, in find_pid
    start_local_couchdb.update_pairing_service()
  File "/usr/lib/python2.6/dist-packages/desktopcouch/start_local_couchdb.py", line 228, in update_pairing_service
    pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
  File "/usr/lib/python2.6/subprocess.py", line 455, in _eintr_retry_call
    return func(*args)
KeyboardInterrupt
    pair_with_ubuntuone()
  File "/usr/lib/python2.6/dist-packages/desktopcouch/pair/couchdb_pairing/ubuntuone_pairing.py", line 55, in pair_with_ubuntuone
    for row in view_results:
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 871, in __iter__
    for row in self.rows:
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 893, in rows
    self._fetch()
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 881, in _fetch
    data = self.view._exec(self.options)
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 766, in _exec
    resp, data = self.resource.get(**self._encode_options(options))
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 978, in get
    return self._request('GET', path, headers=headers, **params)
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 1014, in _request
    resp, data = _make_request()
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 1009, in _make_request
    body=body, headers=headers)
  File "/usr/lib/python2.6/dist-packages/httplib2/__init__.py", line 1129, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/usr/lib/python2.6/dist-packages/httplib2/__init__.py", line 901, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/usr/lib/python2.6/dist-packages/httplib2/__init__.py", line 871, in _conn_request
    response = conn.getresponse()
  File "/usr/lib/python2.6/httplib.py", line 990, in getresponse
    response.begin()
  File "/usr/lib/python2.6/httplib.py", line 391, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.6/httplib.py", line 349, in _read_status
    line = self.fp.readline()
  File "/usr/lib/python2.6/socket.py", line 427, in readline
    data = recv(1)
"""

ProblemType: Bug
DistroRelease: Ubuntu 11.04
Package: desktopcouch 0.6.9b-0ubuntu1
ProcVersionSignature: Ubuntu 2.6.37-7.18-generic 2.6.37-rc3
Uname: Linux 2.6.37-7-generic x86_64
Architecture: amd64
Date: Mon Nov 29 16:22:39 2010
PackageArchitecture: all
ProcEnviron:
 LANGUAGE=en_US:en
 PATH=(custom, user)
 LANG=en_GB.utf8
 SHELL=/bin/bash
SourcePackage: desktopcouch

Related branches

Revision history for this message
Michael Terry (mterry) wrote :
Revision history for this message
Rick Spencer (rick-rickspencer3) wrote :

I tried to reproduce this from a fresh dist-upgrade, and was not able to reproduce it with a new or existing database.

Revision history for this message
Rick Spencer (rick-rickspencer3) wrote :

Ok, I'm hitting this now in other apps, but not in my test app.

Changed in desktopcouch (Ubuntu):
status: New → Confirmed
importance: Undecided → High
Revision history for this message
Michael Terry (mterry) wrote :

I'm moving this package to couchdb because this problem only started happening recently, and desktopcouch hasn't been updated, but couchdb has.

affects: desktopcouch (Ubuntu) → couchdb (Ubuntu)
Changed in couchdb (Ubuntu):
importance: High → Undecided
status: Confirmed → New
Revision history for this message
Michael Terry (mterry) wrote :

whoops, accidentally changed status/importance

Changed in couchdb (Ubuntu):
importance: Undecided → High
status: New → Confirmed
Changed in couchdb (Ubuntu):
assignee: nobody → Chad Miller (cmiller)
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Michael, Rick: you're not using the ubuntone nightlies PPA right? Because that does have a completely new desktopcouch. We didn't knowingly introduce breaking changes, but there may be a bug or two. If not, can you paste some code that we could reproduce this with?

Changed in couchdb (Ubuntu):
assignee: Chad Miller (cmiller) → Eric Casteleijn (thisfred)
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Or is it just that one line and the import that will trigger it?

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

Not very helpful, but on my fully updated maverick machine, it works:

>>> import desktopcouch
>>> from desktopcouch.records.server import CouchDatabase
>>> foo = CouchDatabase('test_db',create=True)
Removing stale, deceptive pid file.
Browse your desktop CouchDB at file:///home/eric/.local/share/desktop-couch/couchdb.html
>>>

Revision history for this message
Michael Terry (mterry) wrote :

This is not using the nightly PPA. It's just stock natty (not maverick). I will try to get a testcase.

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

Aha, I think the new python-couchdb may have just landed in natty, but the desktopcouch version that supports it has not yet. We hope to upload this later today, and hopefully that will solve the issue.

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

Nope python-couchdb has not landed yet, so that's not it. Sry for the noise.

Revision history for this message
Michael Terry (mterry) wrote :
Download full text (3.3 KiB)

Yup, test case is simply:

from desktopcouch.records.server import CouchDatabase
db = CouchDatabase("test-project", create=True)

With output:

Removing stale, deceptive pid file.
Apache CouchDB has started, time to relax.
Browse your desktop CouchDB at file:///home/mike/.local/share/desktop-couch/couchdb.html

And traceback:

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    db = CouchDatabase("test-project", create=True)
  File "/usr/lib/python2.6/dist-packages/desktopcouch/records/server.py", line 56, in __init__
    server_class=server_class, oauth_tokens=oauth_tokens, ctx=ctx)
  File "/usr/lib/python2.6/dist-packages/desktopcouch/records/server_base.py", line 155, in __init__
    self._reconnect()
  File "/usr/lib/python2.6/dist-packages/desktopcouch/records/server.py", line 60, in _reconnect
    port = desktopcouch.find_port(ctx=self.ctx)
  File "/usr/lib/python2.6/dist-packages/desktopcouch/__init__.py", line 106, in find_port
    return _direct_access_find_port(pid=pid, ctx=ctx)
  File "/usr/lib/python2.6/dist-packages/desktopcouch/__init__.py", line 131, in __find_port__linux
    pid = find_pid(start_if_not_running=True, ctx=ctx)
  File "/usr/lib/python2.6/dist-packages/desktopcouch/__init__.py", line 93, in find_pid
    start_local_couchdb.update_pairing_service()
  File "/usr/lib/python2.6/dist-packages/desktopcouch/start_local_couchdb.py", line 228, in update_pairing_service
    pair_with_ubuntuone()
  File "/usr/lib/python2.6/dist-packages/desktopcouch/pair/couchdb_pairing/ubuntuone_pairing.py", line 55, in pair_with_ubuntuone
    for row in view_results:
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 871, in __iter__
    for row in self.rows:
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 893, in rows
    self._fetch()
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 881, in _fetch
    data = self.view._exec(self.options)
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 766, in _exec
    resp, data = self.resource.get(**self._encode_options(options))
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 978, in get
    return self._request('GET', path, headers=headers, **params)
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 1014, in _request
    resp, data = _make_request()
  File "/usr/lib/pymodules/python2.6/couchdb/client.py", line 1009, in _make_request
    body=body, headers=headers)
  File "/usr/lib/python2.6/dist-packages/httplib2/__init__.py", line 1129, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/usr/lib/python2.6/dist-packages/httplib2/__init__.py", line 901, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/usr/lib/python2.6/dist-packages/httplib2/__init__.py", line 871, in _conn_request
    response = conn.getresponse()
  File "/usr/lib/python2.6/httplib.py", line 990, in getresponse
    response.begin()
  File "/usr/lib/python2.6/httplib.py", line 391, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.6/httplib.py", line 349...

Read more...

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

I've tried this both in the interactive shell, and in a test.py running it from the command line, and can't reproduce the hang. Chad, do you have any ideas?

Changed in couchdb (Ubuntu):
assignee: Eric Casteleijn (thisfred) → Chad Miller (cmiller)
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Ah, could it be that there is a keyring prompt open that you missed at the point where the code hangs?

Revision history for this message
Michael Terry (mterry) wrote :

Eric, I don't think it's a keyring prompt. I've done this several times, and haven't seen a prompt (and nothing shows in alt-tab).

Here's an interesting find. If I run the two-line script a second time in a session, it doesn't block. But if I add the following lines, it will hang again reliably on the len(results.rows) line:

results = db.get_records(record_type="http://example.com", create_view=True)
print len(results.rows)

Traceback attached.

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

I still cannot reproduce this behavior on maverick, and since Rick and you both have it on natty, I think it may be a problem unique to that. I'll try and migrate one of my machines to see if I can reproduce.

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

Just to make 100% sure I'm doing exactly the same thing as you, I have a file test_couchdb.py with these (and only these) contents:

from desktopcouch.records.server import CouchDatabase
db = CouchDatabase('test_db3',create=True)
results = db.get_records(record_type="http://example.com", create_view=True)
print len(results.rows)

And I run that from the console (several times) like this:

eric@eric-laptop:~$ python test_couch.py
0
eric@eric-laptop:~$ python test_couch.py
0
eric@eric-laptop:~$ python test_couch.py
0
eric@eric-laptop:~$ python test_couch.py
0

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

Also, if either of you have the time, I would very much like to know if the problem persists with the new version of desktopcouch in our nightlies PPA, since that's what'll be in Natty, and there are some quite substantial changes in that, under the hood, which may impact this behavior.

https://launchpad.net/~ubuntuone/+archive/nightlies

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

It now looks like the problem is the couchdb view server, rather than anything in desktopcouch. I'm investigating this and will move the bug if it turns out to be true.

Changed in couchdb (Ubuntu):
assignee: Chad Miller (cmiller) → Eric Casteleijn (thisfred)
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Yeah it's definitely the js view server that's not working properly, or at all. Investigating where the problem is and how to fix it with Chris Coulson.

Revision history for this message
Chris Coulson (chrisccoulson) wrote :
Download full text (15.1 KiB)

Hmmmm, this might be why:

 #0 0x00000000004031be in readfp (cx=0x18549c0, argc=<value optimised out>, vp=0x7f7559a0f130) at couch_js/main.c:166
         bytes = 0x7f7554001e70 "[\"reset\",{\"reduce_limit\":true}]\n"
         tmp = <value optimised out>
         byteslen = 256
         readlen = <value optimised out>
         used = 140141897195120
 #1 readline (cx=0x18549c0, argc=<value optimised out>, vp=0x7f7559a0f130) at couch_js/main.c:198
         str = <value optimised out>
         bytes = <value optimised out>
         tmp = <value optimised out>
         byteslen = <value optimised out>
 #2 0x00007f755e3760d3 in CallJSNative (cx=0x18549c0, entryFrame=0x7f7559a0f048, inlineCallCount=1, interpMode=JSINTERP_NORMAL) at /build/buildd/xulrunner-2.0-2.0~b7+nobinonly/build-tree/mozilla/js/src/jscntxtinlines.h:684
         ok = <value optimised out>
 #3 js::Interpret (cx=0x18549c0, entryFrame=0x7f7559a0f048, inlineCallCount=1, interpMode=JSINTERP_NORMAL) at /build/buildd/xulrunner-2.0-2.0~b7+nobinonly/build-tree/mozilla/js/src/jsinterp.cpp:4744
         ok = <value optimised out>
         ok = <value optimised out>
         callee = <value optimised out>
         flags = 0
         vp = 0x7f7559a0f130
         newfun = 0x7f7559817f80
         argc = 0
         normalJumpTable = {0x7f755e36e772, 0x7f755e36d9a9, 0x7f755e36c0e6, 0x7f755e36da54, 0x7f755e36db02, 0x7f755e36db35, 0x7f755e36c13e, 0x7f755e36db64, 0x7f755e36dbd3, 0x7f755e36f0ad, 0x7f755e36e254, 0x7f755e36e2d3, 0x7f755e36e6b7, 0x7f755e372fc1, 0x7f755e3730aa, 0x7f755e370157, 0x7f755e3701f2, 0x7f755e37028d, 0x7f755e370328, 0x7f755e36f263, 0x7f755e373bb3, 0x7f755e37322d, 0x7f755e373386, 0x7f755e3723b9, 0x7f755e3739b8, 0x7f755e373916, 0x7f755e373a5a, 0x7f755e3735d4, 0x7f755e373748, 0x7f755e37382f, 0x7f755e373d0c, 0x7f755e36e8f6, 0x7f755e36e9dd, 0x7f755e371eca, 0x7f755e371f32, 0x7f755e371bb5, 0x7f755e371bf7, 0x7f755e371cca, 0x7f755e371d8b, 0x7f755e36c554, 0x7f755e371b5b, 0x7f755e36f828, 0x7f755e371b9d, 0x7f755e371b93, 0x7f755e373b04, 0x7f755e371ba5, 0x7f755e371b98, 0x7f755e36f82d, 0x7f755e36bf98, 0x7f755e36be89, 0x7f755e36f832, 0x7f755e36bf98, 0x7f755e36be89, 0x7f755e36c2d0, 0x7f755e36bad0, 0x7f755e3712d4, 0x7f755e3727f1, 0x7f755e36bc37, 0x7f755e36c452, 0x7f755e36bc37, 0x7f755e36ea52, 0x7f755e36eab8, 0x7f755e36eca5, 0x7f755e36f06a, 0x7f755e36ece8, 0x7f755e3711f7, 0x7f755e36ed2b, 0x7f755e36ed6e, 0x7f755e36dca9, 0x7f755e36dd3b, 0x7f755e36edb1, 0x7f755e36f015, 0x7f755e373b51, 0x7f755e36f48a, 0x7f755e372974, 0x7f755e36e18c, 0x7f755e36e1ec, 0x7f755e36e353, 0x7f755e36c452, 0x7f755e373006, 0x7f755e36eb16, 0x7f755e36d9ec, 0x7f755e372702, 0x7f755e36f01f, 0x7f755e36c5de, 0x7f755e3722e9, 0x7f755e373eb9, 0x7f755e373e61, 0x7f755e3714c9, 0x7f755e36d64d, 0x7f755e36d899, 0x7f755e36cb8d, 0x7f755e36d764, 0x7f755e36f18c, 0x7f755e372e6e, 0x7f755e373b41, 0x7f755e372072, 0x7f755e373b26, 0x7f755e373557, 0x7f755e36e82d, 0x7f755e373b33, 0x7f755e3711ea, 0x7f755e36e794, 0x7f755e37013d, 0x7f755e36e3a4, 0x7f755e36e4f7, 0x7f755e36e645, 0x7f755e36da17, 0x7f755e36ffa8, 0x7f755e3712cf, 0x7f755e36fd31, 0x7f755e36e014, 0x7f755e372a4d, 0x7f755e372af8, 0x7f755e372f53, 0x7f755e3734df, 0x7f755e3729df, 0x7f755e36d965, 0x7f755...

Revision history for this message
Chris Coulson (chrisccoulson) wrote :

Oh, it's probably not clear from the last post, bug couchjs crashes continuously (thanks Apport):

SegvAnalysis:
 Segfault happened at: 0x4031be <readline+94>: cmpb $0xa,(%rax)
 PC (0x004031be) ok
 source "$0xa" ok
 destination "(%rax)" (0xfeeaa8003cdf) not located in a known VMA region (needed writable region)!
SegvReason: writing unknown VMA

Revision history for this message
Chris Coulson (chrisccoulson) wrote :

So, there must be a subtle difference in between fgets and js_fgets. Shame that couchjs can't use the latter any more. I'll take a look at this in the morning anyway

Changed in couchdb (Ubuntu Natty):
assignee: Eric Casteleijn (thisfred) → Chris Coulson (chrisccoulson)
Revision history for this message
Chris Coulson (chrisccoulson) wrote :

fgets and js_fgets really aren't interchangeable. js_fgets is more similar to readline, although the API is still different. I'm pretty sure this is what is causing this bug anyway, and it should be an easy fix

Revision history for this message
Chris Coulson (chrisccoulson) wrote :

I've resorted to using a copy of js_fgets in couchjs, I couldn't find a suitable alternative elsewhere. getline is the closest thing to it, but that has it's own issues:

1) It internally uses malloc, which may not always be the same allocator that spidermonkey uses
2) It reads until a newline, but js_fgets handles newline or carriage return

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package couchdb - 1.0.1-0ubuntu6

---------------
couchdb (1.0.1-0ubuntu6) natty; urgency=low

  * Fix LP: #682866 - CouchDatabase() call hangs because couchjs crashes,
    due to semantic differences between fgets and js_fgets. Use a local
    implementation of js_fgets when it's not available otherwise
    - update debian/patches/mozjs2.0.patch
    - update debian/patches/mozjs2.0_autotools.patch
 -- Chris Coulson <email address hidden> Mon, 06 Dec 2010 10:23:54 +0000

Changed in couchdb (Ubuntu Natty):
status: Confirmed → Fix Released
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Fix confirmed, everything seems to be working great now. Thanks Chris!

Revision history for this message
Chris Coulson (chrisccoulson) wrote :

Excellent, that's good to hear. Thanks for testing

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.