'Connection reset by peer' when replying before the end of POST data

Eric Wong normalperson at yhbt.net
Wed Feb 29 21:36:01 UTC 2012

Lunar <lunar at anargeek.net> wrote:
> With your proposed patch, everything is working as intended. At least, I
> can confirm Firefox correctly display the error message sent by the
> server and not the less understandable "Connection reset by peer". I can
> also confirm that it does not send the complete file: it looks like it
> stops sending as soon as either it notices the socket is closed on its
> write part, or when the response arrives. I am satisfied enough not to
> dive in libxpcom…

Cool, thanks for confirming.  It's good that your client knows to back
off.  My original patch isn't safe for bad clients that send
continously.  Below is a safer version of my original patch, can you
see if it works?

diff --git a/lib/rainbows/client.rb b/lib/rainbows/client.rb
index b456eca..1dcb6d4 100644
--- a/lib/rainbows/client.rb
+++ b/lib/rainbows/client.rb
@@ -6,4 +6,16 @@ class Rainbows::Client < Kgio::Socket
   include Rainbows::ProcessClient
   alias write kgio_write
+  def close
+    close_write
+    kgio_wait_readable(2)
+    buf = ""
+    case kgio_tryread(512, buf)
+    when nil, Symbol
+      break
+    end while true
+    ensure
+      super
+  end

> I could see it part of Rainbows!, as optional behaviour, off by default
> if you'd prefer, but I am fine either way.

I'll probably call it "lingering_close" like nginx calls it.  Of course
this needs to be supported for EM/Cool.io, too.

More information about the rainbows-talk mailing list