unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: mongrel-unicorn@rubyforge.org
Subject: [PATCH 1/2] http_server: improve handling of client-triggerable socket errors
Date: Sat, 17 Aug 2013 01:20:11 +0000	[thread overview]
Message-ID: <1376702412-13562-2-git-send-email-normalperson@yhbt.net> (raw)
In-Reply-To: <1376702412-13562-1-git-send-email-normalperson@yhbt.net>

We do not attempt to write HTTP responses for socket errors if
clients disconnect from us unexpectedly.

Additionally, we do not hide backtraces EINVAL/EBADF errors, since
they are indicative of real bugs which must be fixed.

We do continue to hide hide EOF, ECONNRESET, ENOTCONN, and EPIPE
because clients (even "friendly") ones will break connections due to
client crashes or network failure (which is common for me :P), and
the backtraces from those will cause excessive logging and even
become a DoS vector.
---
 lib/unicorn/http_server.rb | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb
index cc0a705..bed24d0 100644
--- a/lib/unicorn/http_server.rb
+++ b/lib/unicorn/http_server.rb
@@ -520,9 +520,8 @@ def maintain_worker_count
   # the socket is closed at the end of this function
   def handle_error(client, e)
     code = case e
-    when EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL,Errno::EBADF,
-         Errno::ENOTCONN
-      500
+    when EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::ENOTCONN
+      # client disconnected on us and there's nothing we can do
     when Unicorn::RequestURITooLongError
       414
     when Unicorn::RequestEntityTooLargeError
@@ -533,7 +532,9 @@ def handle_error(client, e)
       Unicorn.log_error(@logger, "app error", e)
       500
     end
-    client.kgio_trywrite(err_response(code, @request.response_start_sent))
+    if code
+      client.kgio_trywrite(err_response(code, @request.response_start_sent))
+    end
     client.close
     rescue
   end
-- 
1.8.3.2.701.g8c4e4ec

_______________________________________________
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

  reply	other threads:[~2013-08-17  1:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-17  1:20 [PATCH 0/2] minor improvements pushed to unicorn.git Eric Wong
2013-08-17  1:20 ` Eric Wong [this message]
2013-08-17  1:20 ` [PATCH 2/2] test_util: fix encoding test for Ruby trunk (2.1.0dev) Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/unicorn/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1376702412-13562-2-git-send-email-normalperson@yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=mongrel-unicorn@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).