Jesse Storimer <[email protected]> wrote: > Eric Wong <[email protected]> wrote: > > Unicorn has 4 distinct states :
<snip> > > 3) inside Rack dispatch (after rack.input reading) > > Your app has no way of knowing your client disconnected at > > this stage. You can hack Unicorn to IO.select in a separate > > thread, but there'll always be exposed windows leading up to > > 4) so it's not worth it... > > > > 4) writing the response: Unicorn will abort whenever a socket > > error is detected. Keep in mind that every single part of the > > Rack response array can be dynamically generated by the app. > > Your application can still be "running" even though the Rack app > > has returned its response for Unicorn to start writing. > > > > Clients/Rack middleware can be written to detect this in the > > response body "close" method by checking if body.each completed. > > Thanks for that explanation. Just so I understand, once the Rack application > enters 3) then it should be unaffected by a client disconnect, or any > socket error? I'll definitely give PrereadInput a try in that case. Yes, however I don't think I made it clear that 3) will /always/ transition to state 4). So you'll be able to use body.close to detect a client write failure. > When you say that Unicorn lazily reads request bodies, do you mean that > my Rails application might already be in the middle of processing the > request but Unicorn is still reading from the client socket? Yes. We use http://unicorn.bogomips.org/Unicorn::TeeInput.html by default so it gives the Rack app a chance to reject a client if it sees something it doesnt like > At that point won't Rails have read all of the request body? Or does > that only apply if I stick a middleware at the front of the stack that > does all the heavy lifting? I'm not certain about middlewares. Rails may attempt to read all input ASAP anyways depending on the request Content-Type/Encoding. Check the Rails/Rack sources for your versions of Rails/Rack to be sure. -- Eric Wong _______________________________________________ Unicorn mailing list - [email protected] http://rubyforge.org/mailman/listinfo/mongrel-unicorn Do not quote signatures (like this one) or top post when replying
