unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: Dylan Thacker-Smith <dylan.smith@shopify.com>
Cc: unicorn-public@bogomips.org
Subject: Re: [PATCH] Check for Socket::TCP_INFO constant before trying to get TCP_INFO
Date: Sun, 26 Mar 2017 02:41:12 +0000	[thread overview]
Message-ID: <20170326024112.GA28554@starla> (raw)
In-Reply-To: <20170326014903.54312-1-Dylan.Smith@shopify.com>

Dylan Thacker-Smith <dylan.smith@shopify.com> wrote:
> The ruby constant Socket::TCP_INFO is only defined if TCP_INFO is defined
> in C, so we can just check for the presence of that ruby constant instead
> of rescuing SocketError from the call to getsockopt.

Good catch!  I forget there's systems without TCP_INFO at all :x

> +++ 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 = nil
> +  @@tcpi_inspect_ok = Socket.const_defined?(:TCP_INFO)
>  
>    def self.input_class
>      @@input_class
> @@ -154,20 +154,10 @@ def closed_state?(state) # :nodoc:
>      # 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 != 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 Unicorn::TCPClient === socket && @@tcpi_inspect_ok
> +        opt = socket.getsockopt(Socket::IPPROTO_TCP, Socket::TCP_INFO).inspect
>          if opt =~ /\bstate=(\S+)/
> +          @@tcpi_inspect_ok = true

Is the last line to set "@@tcpi_inspect_ok = true" still
necessary?  It was necessary in Jeremy's version, but I think
you can safely omit it, now.

>            raise Errno::EPIPE, "client closed connection".freeze,
>                  EMPTY_ARRAY if closed_state_str?($1)
>          else

Anyways, I'm inclined to apply your patch with the redundant
assignment removed (no need to resend).  Thanks.

  reply	other threads:[~2017-03-26  2:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-26  1:49 [PATCH] Check for Socket::TCP_INFO constant before trying to get TCP_INFO Dylan Thacker-Smith
2017-03-26  2:41 ` Eric Wong [this message]
2017-03-26  2:52   ` Dylan Thacker-Smith
2017-03-26  3:37     ` 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=20170326024112.GA28554@starla \
    --to=e@80x24.org \
    --cc=dylan.smith@shopify.com \
    --cc=unicorn-public@bogomips.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).