[Web-SIG] Most WSGI servers close connections to early.

And Clover and-py at doxdesk.com
Mon Sep 27 11:15:04 CEST 2010

On 09/22/2010 02:46 PM, Marcel Hellkamp wrote:
> "An application should read all available data from
> `environ['wsgi.input']` on POST or PUT requests, even if it does not
> process that data. Otherwise, the client might fail to complete the
> request and not display the response."

Oh, it's worse than that. In practice the application needs to read all 
available data from the request body before producing output.

If you send too much response without reading the whole request body in 
some environments, you can deadlock. The web server is buffering the 
input stream for the request body and also the output stream from the 
app. This needs to be done[1] to avoid sending an HTTP response before 
the request is complete.

If those are limited-size buffers[2] and you fill the output buffer with 
response without clearing enough of the input buffer that the browser 
can finish sending the request, you'll be blocking indefinitely on write.

[1] possibly unless HTTP pipelining is in effect? not sure, haven't tested.

[2] and certainly in IIS they are. The output buffer is 8K IIRC. It's 
easy to overflow that and get a mysterious non-responsive script because 
an error happens and spits out a debugging page before the form-reading 
library has had a chance to consume the input.

And Clover
mailto:and at doxdesk.com

More information about the Web-SIG mailing list