[Python-bugs-list] [ python-Bugs-666219 ] AssertionErrors in httplib

SourceForge.net noreply@sourceforge.net
Thu, 20 Mar 2003 10:43:38 -0800


Bugs item #666219, was opened at 2003-01-11 08:23
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=666219&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Skip Montanaro (montanaro)
Assigned to: Jeremy Hylton (jhylton)
Summary: AssertionErrors in httplib

Initial Comment:
I've recently noticed AssertionErrors being raised by
httplib.LineAndFileWrapper.read().  It happens reliably when the server
exits unexpectedly.  Here's an example of an AssertionError in an 
xmlrpclib client when I kill the server it's talking to:

    Traceback (most recent call last):
      File "qa.py", line 22, in ?
        x = s.query(tmpl, st, en, radius, age)
      File "/Users/skip/local/lib/python2.3/xmlrpclib.py", line 985, in __call__
        return self.__send(self.__name, args)
      File "/Users/skip/local/lib/python2.3/xmlrpclib.py", line 1269, in __request
        verbose=self.__verbose
      File "/Users/skip/local/lib/python2.3/xmlrpclib.py", line 1036, in request
        return self._parse_response(h.getfile(), sock)
      File "/Users/skip/local/lib/python2.3/xmlrpclib.py", line 1165, in _parse_response
        response = file.read(1024)
      File "/Users/skip/local/lib/python2.3/httplib.py", line 1150, in read
        assert not self._line_consumed and self._line_left
    AssertionError

I don't see a problem with raising an exception in this situation.  I just
wonder if AssertionError is the best exception to raise (unless of course, the cause is a logic error in the httplib code).  If an exception
is being raised because the server went away, I think it would be 
better to raise IncompleteRead.

----------------------------------------------------------------------

>Comment By: Skip Montanaro (montanaro)
Date: 2003-03-20 12:43

Message:
Logged In: YES 
user_id=44345

Sorry for the delay on this.  I think I'm closing in on the
problem.  I've been using Tim O'Malley's timeoutsocket
module for quite awhile.  I noticed the same problem today
when using the new timeout feature in the socket module.
Libraries like xmlrpclib use makefile() to get a file object
to play with.  File objects don't play well with timeouts
because the socket is in non-blocking mode.  I think what
happens here is that the first line of HTTPResponse.
_read_status sets line to the empty string because of the
timeout setting.  Tracing through the code which follows
makes it clear that control will wind up in the HTTP/0.9
chunk of code.

Maybe it's worth adding a test for line == "" after the
readline() call:

        line = self.fp.readline()
        if self.debuglevel > 0:
            print "reply:", repr(line)
        if line == "":
            raise BadStatusLine(line)

That would distinguish an error reading from an 0.9 server
(which would return something with that first readline()
call).

----------------------------------------------------------------------

Comment By: Skip Montanaro (montanaro)
Date: 2003-01-31 08:13

Message:
Logged In: YES 
user_id=44345

No, sorry, I haven't looked more deeply into the problem.  I did investigate
far enough to also see that the code was in the HTTP/0.9 weeds and am
befuddled about why it would be there.  It's using the vanilla xmlrpclib
module at both ends.  I'll try to spend a little time today.

S

----------------------------------------------------------------------

Comment By: Jeremy Hylton (jhylton)
Date: 2003-01-31 08:07

Message:
Logged In: YES 
user_id=31392

Any more info Skip?


----------------------------------------------------------------------

Comment By: Jeremy Hylton (jhylton)
Date: 2003-01-14 15:18

Message:
Logged In: YES 
user_id=31392

It's definitely the case that an AssertionError shouldn't be
raised.  It was my intention that the assert never fail.  Do
you know which part of the assert fails?  Perhaps you could
change the assert to print the values of _line_consumed and
_line_left and run some more tests.
I can't figure out how this goes wrong.

Also, do you know when the server is sending an HTTP/0.9
response?  I wonder if there's a bug somewhere else and the
client is guessing the wrong protocol version for the response.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=666219&group_id=5470