Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

cannot retrieve headers at time of exception (e.g. NoMoreData) #74

Closed
wohali opened this Issue Sep 8, 2011 · 7 comments

Comments

Projects
None yet
3 participants

wohali commented Sep 8, 2011

Sometimes a connection does not return all expected data and throws a NoMoreData exception. When the exception is caught it would be good to review the full response so as to better diagnose what went wrong from the server. This is not possible now; the only solution is to turn on full restkit debugging (which can be very noisy, and doesn't help an end user).

CouchDB generates InvalidChunkSizes when it terminates a connection, but this is because the real reason for the failure is in that last block (which doesn't match the expected chunk size).

NoMoreData, InvalidChunkSize and so on should return the full headers/body if possible for review by the application so that appropriate steps can be taken to recover from the error (and, help find the root cause of the CouchDB error!)

Owner

benoitc commented Sep 19, 2011

Can't you log the headers before doing the request and then check later? Do you do a resp.get_body_string or do you use the stream api?

btw ow can I reproduced this error so it can be eventually fixed in couch?

dsully commented Jan 27, 2012

I'm seeing a similar issue - getting a NoMoreData exception when I upgraded to 4.0.0, but it's only reproducible via running my entire test suite, not just the single test class that is failing (other tests use the class that fails, but successfully)

Traceback (most recent call last):
File "/Users/dsully/.virtualenvs/linkedin/lib/python2.6/site-packages/nose/case.py", line 381, in setUp
try_run(self.inst, ('setup', 'setUp'))
File "/Users/dsully/.virtualenvs/linkedin/lib/python2.6/site-packages/nose/util.py", line 478, in try_run
return func()
File "/Users/dsully/dev/tools/lib/utils/test/test_warutils.py", line 9, in setup
self.warinfo = WarInfo()
File "/Users/dsully/dev/tools/lib/utils/src/linkedin/utils/warutils.py", line 13, in init
self.service_map = jprops.load_properties(download(properties_url))
File "/Users/dsully/dev/tools/lib/utils/src/linkedin/utils/http.py", line 33, in download
response = Client(url, debug=debug, follow_redirect=True).get()
File "/Users/dsully/.virtualenvs/linkedin/lib/python2.6/site-packages/restkit/resource.py", line 114, in get
params_dict=params_dict, *_params)
File "/Users/dsully/dev/tools/lib/utils/src/linkedin/utils/http.py", line 141, in request
return super(Client, self).request(method, path, payload, headers, params_dict, *_params)
File "/Users/dsully/.virtualenvs/linkedin/lib/python2.6/site-packages/restkit/resource.py", line 190, in request
headers=self.make_headers(headers))
File "/Users/dsully/.virtualenvs/linkedin/lib/python2.6/site-packages/restkit/client.py", line 403, in request
return self.perform(request)
File "/Users/dsully/.virtualenvs/linkedin/lib/python2.6/site-packages/restkit/client.py", line 355, in perform
return self.get_response(request, conn)
File "/Users/dsully/.virtualenvs/linkedin/lib/python2.6/site-packages/restkit/client.py", line 437, in get_response
log.debug("Got response: %s" % p.status())
File "/Users/dsully/.virtualenvs/linkedin/lib/python2.6/site-packages/http_parser/http.py", line 104, in status
status_code = self.status_code()
File "/Users/dsully/.virtualenvs/linkedin/lib/python2.6/site-packages/http_parser/http.py", line 99, in status_code
self._check_headers_complete()
File "/Users/dsully/.virtualenvs/linkedin/lib/python2.6/site-packages/http_parser/http.py", line 67, in _check_headers_complete
raise NoMoreData()
NoMoreData:

If I downgrade to 3.3.2, problem goes away.

The server side looks fine - it's Apache vending Subversion.

What data would be useful for debugging?

Thanks.

Owner

benoitc commented Jan 27, 2012

hum if you see them in 4.0 they should also appear in the 3.3.2 that's odd. can you set the reskti debugging to the debug level?

dsully commented Jan 27, 2012

3.3.2 Debugging:

[DEBUG] 2012-01-27 12:22:05,678 restkit.client - Start to perform request: svn.corp.linkedin.com HEAD /relrepo/deployment/global/topology.xml
[DEBUG] 2012-01-27 12:22:05,678 restkit.client - create new connection
[DEBUG] 2012-01-27 12:22:05,682 restkit.client - Send headers: ['HEAD /relrepo/deployment/global/topology.xml HTTP/1.1\r\n', 'Host: svn.corp.linkedin.com\r\n', 'User-Agent: Python-HTTP-Client/1.0 (Darwin; U; CPU x86_64) restkit/3.3.2; 1.py\r\n', 'Accept-Encoding: compress, gzip\r\n', 'User_Agent: Python-HTTP-Client/1.0 (Darwin; U; CPU x86_64) restkit/3.3.2; 1.py\r\n', 'Accept: application/json\r\n']
[DEBUG] 2012-01-27 12:22:05,682 restkit.client - Start to parse response
[DEBUG] 2012-01-27 12:22:05,685 restkit.client - Got response: 200 OK
[DEBUG] 2012-01-27 12:22:05,685 restkit.client - headers: [IOrderedDict([('Date', 'Fri, 27 Jan 2012 20:22:05 GMT'), ('Server', 'Apache/2.2.15 (Red Hat)'), ('Last-Modified', 'Thu, 26 Jan 2012 23:00:57 GMT'), ('ETag', '"53378//deployment/global/topology.xml"'), ('Accept-Ranges', 'bytes'), ('Content-Length', '348272'), ('Content-Type', 'text/plain; charset=UTF-8')])]
[DEBUG] 2012-01-27 12:22:05,686 restkit.conn - release connection
[DEBUG] 2012-01-27 12:22:05,686 restkit.client - return response class

4.0.0 Debugging:

[DEBUG] 2012-01-27 12:21:42,944 restkit.client - Start to perform request: svn.corp.linkedin.com HEAD /relrepo/deployment/global/topology.xml
[DEBUG] 2012-01-27 12:21:42,946 restkit.client - Send headers: ['HEAD /relrepo/deployment/global/topology.xml HTTP/1.1\r\n', 'Host: svn.corp.linkedin.com\r\n', 'User-Agent: Python-HTTP-Client/1.0 (Darwin; U; CPU x86_64) restkit/4.0.0; 1.py\r\n', 'Accept-Encoding: compress, gzip\r\n', 'User_Agent: Python-HTTP-Client/1.0 (Darwin; U; CPU x86_64) restkit/4.0.0; 1.py\r\n', 'Accept: application/json\r\n']
[DEBUG] 2012-01-27 12:21:42,946 restkit.client - Start to parse response
[DEBUG] 2012-01-27 12:21:42,948 restkit.client - Got response: 200 OK
[DEBUG] 2012-01-27 12:21:42,948 restkit.client - headers: [IOrderedDict([('Date', 'Fri, 27 Jan 2012 20:21:42 GMT'), ('Server', 'Apache/2.2.15 (Red Hat)'), ('Last-Modified', 'Thu, 26 Jan 2012 23:00:57 GMT'), ('ETag', '"53378//deployment/global/topology.xml"'), ('Accept-Ranges', 'bytes'), ('Content-Length', '348272'), ('Content-Type', 'text/plain; charset=UTF-8')])]
[DEBUG] 2012-01-27 12:21:42,948 restkit.client - return response class

As I mentioned, in isolation, it works fine - there is something that is causing it to get triggered when running as part of a test suite via nosetests.

dsully commented Jan 27, 2012

Ok, I've narrowed it down to a runnable test case / interaction with flufl.lock when using restkit 4.0.0

The remote URL seems to need to be a Subversion server. Pointing it at http://www.google.com/ doesn't cause the error.

from datetime import timedelta
from flufl.lock import Lock, TimeOutError, AlreadyLockedError
from restkit.client import Client

url = 'http://gcc.gnu.org/svn/gcc/trunk/Makefile.in'

print "GETing %s" % url
Client().request(url).body_string()

##################################
# test_break_lifetime_expired_lock
lockfile = "/tmp/foo"

print "Trying to acquire lock 1"
lock1 = Lock(lockfile, lifetime=timedelta(seconds=1))
lock1.lock()

print "Trying to acquire lock 2"
lock2 = Lock(lockfile)
lock2.lock()
lock2.unlock()

##############
# test_timeout
print "Trying to acquire lock 3"
lock1 = Lock(lockfile)
lock1.lock()

print "Trying to acquire lock 4"
lock2 = Lock(lockfile)

tries = 3

for i in xrange(tries, 0, -1):
  try:
    lock2.lock(timedelta(seconds=1))
    break
  except TimeOutError as e:
    print e

lock1.unlock()

print "GETing %s" % url
Client().request(url).body_string()
Owner

benoitc commented Jan 27, 2012

last change in socketpool (last head) seems to fix it. Let me know

dsully commented Jan 28, 2012

The socketpool fix appears to work. Sorry for hijacking this issue.

@benoitc benoitc closed this in 1f15e1d Jan 31, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment