* [PATCH 1/2] http_server: improve handling of client-triggerable socket errors
2013-08-17 1:20 [PATCH 0/2] minor improvements pushed to unicorn.git Eric Wong
@ 2013-08-17 1:20 ` Eric Wong
2013-08-17 1:20 ` [PATCH 2/2] test_util: fix encoding test for Ruby trunk (2.1.0dev) Eric Wong
1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2013-08-17 1:20 UTC (permalink / raw)
To: mongrel-unicorn
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] test_util: fix encoding test for Ruby trunk (2.1.0dev)
2013-08-17 1:20 [PATCH 0/2] minor improvements pushed to unicorn.git Eric Wong
2013-08-17 1:20 ` [PATCH 1/2] http_server: improve handling of client-triggerable socket errors Eric Wong
@ 2013-08-17 1:20 ` Eric Wong
1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2013-08-17 1:20 UTC (permalink / raw)
To: mongrel-unicorn
As of r40610 in ruby trunk, internal encoding is ignored if
external coding is ASCII-8BIT (binary)
ref: r40610 http://svn.ruby-lang.org/repos/ruby/trunk
---
test/unit/test_util.rb | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/test/unit/test_util.rb b/test/unit/test_util.rb
index b8e4043..904d51c 100644
--- a/test/unit/test_util.rb
+++ b/test/unit/test_util.rb
@@ -80,7 +80,11 @@ def test_reopen_logs_renamed_with_internal_encoding
File.open(tmp_path, "a:#{ext.to_s}:#{int.to_s}") { |fp|
fp.sync = true
assert_equal ext, fp.external_encoding
- assert_equal int, fp.internal_encoding
+
+ if ext != Encoding::BINARY
+ assert_equal int, fp.internal_encoding
+ end
+
File.unlink(tmp_path)
assert ! File.exist?(tmp_path)
Unicorn::Util.reopen_logs
@@ -88,7 +92,9 @@ def test_reopen_logs_renamed_with_internal_encoding
assert File.exist?(tmp_path)
assert_equal fp.stat.inspect, File.stat(tmp_path).inspect
assert_equal ext, fp.external_encoding
- assert_equal int, fp.internal_encoding
+ if ext != Encoding::BINARY
+ assert_equal int, fp.internal_encoding
+ end
assert_equal(EXPECT_FLAGS, EXPECT_FLAGS & fp.fcntl(Fcntl::F_GETFL))
assert fp.sync
}
--
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
^ permalink raw reply related [flat|nested] 3+ messages in thread