Author jasondavies
Recipients jasondavies
Date 2009-03-23.09:29:06
SpamBayes Score 4.98931e-05
Marked as misclassified No
Message-id <>
I came across this bug when trying to use CouchDB-Python to PUT an
attachment using HTTP authentication (using the httplib2 library). 
Essentially what httplib2 does is this:

1. Attempt PUT with no auth credentials
2. If a 401 response is received, try again with credentials

However, CouchDB sends a 401 response as soon as it has consumed the
request headers, and before the request body has been fully sent by the

This triggers a bug in both httplib and httplib2, whereby they raise
exceptions due to a broken pipe being encountered when trying to finish
sending the request body.

It seems that Python's httplib checks for broken pipe errors and closes
the connection entirely when they occur when making a request.  This is
unhelpful if a legitimate response was sent and the socket was closed
early by the server.

The offending try/except handler is in httplib.HttpConnection.send and
has a comment saying:

# send the data to the server. if we get a broken pipe, then close
# the socket. we want to reconnect when somebody tries to send again.

This is wrong, as someone might want to read the response before closing
the socket.

For reference, the CouchDB-Python issue is:

This bug may also be related to:
Date User Action Args
2009-03-23 09:29:11jasondaviessetrecipients: + jasondavies
2009-03-23 09:29:10jasondaviessetmessageid: <>
2009-03-23 09:29:09jasondavieslinkissue5542 messages
2009-03-23 09:29:06jasondaviescreate