Author jvmiller
Recipients jvmiller
Date 2010-08-09.22:08:55
SpamBayes Score 5.48429e-10
Marked as misclassified No
Message-id <1281391740.65.0.539097127829.issue9550@psf.upfronthosting.co.za>
In-reply-to
Content
While reading, BufferedReader can cause an additional read() to the underlying I/O object after the entire upper-layer byte count has been satisfied. This is unnecessary and troublesome in some cases.

In the event that the BufferedReader sits on top of a blocking socket (see the included test case,) certain network protocols (HTTP) can cause the server to hang in recv/recvfrom trying to read more data than will be available, causing a hang. I first ran into this issue running bottle on top of the core Python wsgi server.

It looks as though this may be present in 2.x as well, however an associate of mine wasn't able to trigger the issue in 2.x (even after implementing the makefile() code from 3.x)

To run the test case, start the server and then run the client against it.

bufio.py server
bufio.py client

I successfully patched this issue locally with the following:

---
Modules/_io/bufferedio.c:

    self->pos = 0;
    self->raw_pos = 0;
    self->read_end = 0;

+   if ( remaining == 0 )
+       return res;
+

    while (self->read_end < self->buffer_size) {
---

Which aborts execution of the second loop in the event that the last block-sized read satisfied the upper layer call exactly.
History
Date User Action Args
2010-08-09 22:09:00jvmillersetrecipients: + jvmiller
2010-08-09 22:09:00jvmillersetmessageid: <1281391740.65.0.539097127829.issue9550@psf.upfronthosting.co.za>
2010-08-09 22:08:58jvmillerlinkissue9550 messages
2010-08-09 22:08:56jvmillercreate