diff options
author | Jeremy Evans <code@jeremyevans.net> | 2017-03-24 13:03:46 -0700 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2017-03-24 21:06:59 +0000 |
commit | 9cced5d3ace9fc333c95b63f443225887f774a47 (patch) | |
tree | 0bcc7b9f8ac03cfe70c2fbe9b9158185a1a6df15 | |
parent | d60cab29c91aec17859539f389e343f799b6f1b9 (diff) | |
download | unicorn-9cced5d3ace9fc333c95b63f443225887f774a47.tar.gz |
On OpenBSD, getsockopt(2) does not support TCP_INFO. With the current code, this results in a 500 for all clients if check_client_connection is enabled on OpenBSD. This patch rescues SocketError on the first getsockopt call, and if SocketError is raised, it doesn't check in the future. This should be the same behavior as if TCP_INFO was supported but inspect did not return a string in the expected format.
-rw-r--r-- | lib/unicorn/http_request.rb | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index 7253497..6dc0aa7 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -29,7 +29,7 @@ class Unicorn::HttpParser EMPTY_ARRAY = [].freeze @@input_class = Unicorn::TeeInput @@check_client_connection = false - @@tcpi_inspect_ok = true + @@tcpi_inspect_ok = nil def self.input_class @@input_class @@ -154,10 +154,20 @@ class Unicorn::HttpParser # Not that efficient, but probably still better than doing unnecessary # work after a client gives up. def check_client_connection(socket) # :nodoc: - if Unicorn::TCPClient === socket && @@tcpi_inspect_ok - opt = socket.getsockopt(:IPPROTO_TCP, :TCP_INFO).inspect - if opt =~ /\bstate=(\S+)/ + if Unicorn::TCPClient === socket && @@tcpi_inspect_ok != false + if @@tcpi_inspect_ok + opt = socket.getsockopt(:IPPROTO_TCP, :TCP_INFO).inspect + else @@tcpi_inspect_ok = true + opt = begin + socket.getsockopt(:IPPROTO_TCP, :TCP_INFO) + rescue SocketError + @@tcpi_inspect_ok = false + return write_http_header(socket) + end.inspect + end + + if opt =~ /\bstate=(\S+)/ raise Errno::EPIPE, "client closed connection".freeze, EMPTY_ARRAY if closed_state_str?($1) else |