From 3339999f18ad058bfccd8b7daccf16056decf129 Mon Sep 17 00:00:00 2001 From: Sean Goedecke Date: Tue, 18 May 2021 10:41:10 +1000 Subject: [PATCH 1/3] Treat low_latency=false as false instead of true Previously the binder.parse code was just checking that the low_latency key existed, but the docs (and other options) support passing options in the format `option=false`. This commit now treats `low_latency=false` as false, while still treating `low_latency` with no `=` as true --- lib/puma/binder.rb | 2 +- test/test_binder.rb | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/puma/binder.rb b/lib/puma/binder.rb index 44b64be56b..f8939ac2e9 100644 --- a/lib/puma/binder.rb +++ b/lib/puma/binder.rb @@ -163,7 +163,7 @@ def parse(binds, logger, log_msg = 'Listening') ios_len = @ios.length params = Util.parse_query uri.query - opt = params.key?('low_latency') + opt = params.key?('low_latency') && params['low_latency'] != 'false' bak = params.fetch('backlog', 1024).to_i io = add_tcp_listener uri.host, uri.port, opt, bak diff --git a/test/test_binder.rb b/test/test_binder.rb index af28d82106..09204d09a2 100644 --- a/test/test_binder.rb +++ b/test/test_binder.rb @@ -192,6 +192,30 @@ def test_pre_existing_unix end end + def test_binder_parses_nil_low_latency + @binder.parse ["tcp://0.0.0.0:0?low_latency"], @events + + socket = @binder.listeners.first.last + + assert socket.getsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY).bool + end + + def test_binder_parses_true_low_latency + @binder.parse ["tcp://0.0.0.0:0?low_latency=true"], @events + + socket = @binder.listeners.first.last + + assert socket.getsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY).bool + end + + def test_binder_parses_false_low_latency + @binder.parse ["tcp://0.0.0.0:0?low_latency=false"], @events + + socket = @binder.listeners.first.last + + refute socket.getsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY).bool + end + def test_binder_parses_tlsv1_disabled skip_unless :ssl @binder.parse ["ssl://0.0.0.0:0?#{ssl_query}&no_tlsv1=true"], @events From ffacfdb9861a3305b1c4f753de0739e0e46813a9 Mon Sep 17 00:00:00 2001 From: Sean Goedecke Date: Tue, 18 May 2021 10:43:01 +1000 Subject: [PATCH 2/3] Update docs to reflect code behaviour --- lib/puma/dsl.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puma/dsl.rb b/lib/puma/dsl.rb index c6f429efb4..c4c66813ae 100644 --- a/lib/puma/dsl.rb +++ b/lib/puma/dsl.rb @@ -201,7 +201,7 @@ def load(file) # * Set the socket backlog depth with +backlog+, default is 1024. # * Set up an SSL certificate with +key+ & +cert+. # * Set whether to optimize for low latency instead of throughput with - # +low_latency+, default is to optimize for low latency. This is done + # +low_latency+, default is to not optimize for low latency. This is done # via +Socket::TCP_NODELAY+. # * Set socket permissions with +umask+. # From 331cc760c5ad3ce3c29a56f59f8d4223c9004f31 Mon Sep 17 00:00:00 2001 From: Sean Goedecke Date: Wed, 19 May 2021 10:59:31 +1000 Subject: [PATCH 3/3] Skip getsockopt tests in JRuby JRuby (at least this version) doesn't support basic Socket constants or methods Ref: https://github.com/jruby/jruby/issues/3438 --- test/test_binder.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/test_binder.rb b/test/test_binder.rb index 09204d09a2..c4a027ab62 100644 --- a/test/test_binder.rb +++ b/test/test_binder.rb @@ -193,6 +193,7 @@ def test_pre_existing_unix end def test_binder_parses_nil_low_latency + skip_if :jruby @binder.parse ["tcp://0.0.0.0:0?low_latency"], @events socket = @binder.listeners.first.last @@ -201,6 +202,7 @@ def test_binder_parses_nil_low_latency end def test_binder_parses_true_low_latency + skip_if :jruby @binder.parse ["tcp://0.0.0.0:0?low_latency=true"], @events socket = @binder.listeners.first.last @@ -209,6 +211,7 @@ def test_binder_parses_true_low_latency end def test_binder_parses_false_low_latency + skip_if :jruby @binder.parse ["tcp://0.0.0.0:0?low_latency=false"], @events socket = @binder.listeners.first.last