Author martin.panter
Recipients martin.panter
Date 2015-02-02.12:56:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1422881776.12.0.998068930599.issue23377@psf.upfronthosting.co.za>
In-reply-to
Content
This is the same issue raised at <https://bugs.python.org/issue4879#msg91597>. Currently, every time a new response is to be received, HTTPConnection passes its raw socket object to HTTPResponse, which calls sock.makefile("rb") and creates a BufferedReader. The BufferedReader is used to parse the header section and read the response body. The problem is that the BufferedReader is closed at the end of reading the response, potentially losing buffered data read from a subsequent response.

Normally no data is lost, because most users would read the full response before triggering a new request, and the server would wait for a request before sending a response. But if a user pipelined a second request without reading all of the first response, and the server happened to send the end of the first response and the start of the second response in the same packet, it could trigger the problem. I have added a test called test_httplib.ServerTest.testDoubleResponse() which emulates this scenario. The problem also makes it hard to detect misbehaving servers, or use HTTPConnection to test that a server is behaving correctly.

I am adding a patch which creates the BufferedReader once for each connection. This involves changing the API of the HTTPResponse constructor. I think this should be okay because even though it is documented, it says “Not instantiated directly by user”. It did require changing the tests that call the HTTPResponse constructor though. If absolutely necessary, it may be possible to maintain backwards compatibility if we added a new constructor parameter, and carefully juggled how the close() calls work.
History
Date User Action Args
2015-02-02 12:56:17martin.pantersetrecipients: + martin.panter
2015-02-02 12:56:16martin.pantersetmessageid: <1422881776.12.0.998068930599.issue23377@psf.upfronthosting.co.za>
2015-02-02 12:56:16martin.panterlinkissue23377 messages
2015-02-02 12:56:15martin.pantercreate