unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* TCP reset and socket buffer draining responsibility
@ 2010-03-15 14:32 John Fieber
  2010-03-15 17:48 ` Eric Wong
  0 siblings, 1 reply; 2+ messages in thread
From: John Fieber @ 2010-03-15 14:32 UTC (permalink / raw)
  To: unicorn list

I have a bug where some Rack middleware that determines certain PUT/POST error responses without needing to read the request body.  On Linux, this causes a TCP reset when Unicorn closes the socket with unread data in the input buffer.  The reset preempts the delivery written but still buffered response, so client receives a simple RST and no response.   If I inject some read-buffer draining code just before the close, the problem goes away.

The RST behavior is obviously not desired, but my question is what level of the stack is responsible for making sure it doesn't happen?  It strikes me that Unicorn is in the best position to do it efficiently and reliably, but anything higher up can also do it.

Thoughts?

-john

_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: TCP reset and socket buffer draining responsibility
  2010-03-15 14:32 TCP reset and socket buffer draining responsibility John Fieber
@ 2010-03-15 17:48 ` Eric Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2010-03-15 17:48 UTC (permalink / raw)
  To: unicorn list

John Fieber <jfieber@adobe.com> wrote:
> I have a bug where some Rack middleware that determines certain
> PUT/POST error responses without needing to read the request body.  On
> Linux, this causes a TCP reset when Unicorn closes the socket with
> unread data in the input buffer.  The reset preempts the delivery
> written but still buffered response, so client receives a simple RST
> and no response.   If I inject some read-buffer draining code just
> before the close, the problem goes away.
> 
> The RST behavior is obviously not desired, but my question is what
> level of the stack is responsible for making sure it doesn't happen?
> It strikes me that Unicorn is in the best position to do it
> efficiently and reliably, but anything higher up can also do it.

Hi John,

You have to use the read buffer draining code in your app or middleware.

The Unicorn::TeeInput class doesn't read off the socket until it needs
to.  This is because Rack requires the input stream to be rewindable,
and the input stream being rewindable means it must be buffered to a
temporary file which could potentially fill up the disk (especially with
chunked input that doesn't declare a Content-Length).

So Unicorn gives apps/middleware control to cut off uploading clients in
this case.

-- 
Eric Wong
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-03-15 17:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-15 14:32 TCP reset and socket buffer draining responsibility John Fieber
2010-03-15 17:48 ` Eric Wong

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/unicorn.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).