mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Fixed the issue of @listeners getting nil io (#1120)
* Fixed the issue of @listeners getting nil io - `add_tcp_listener` and `add_ssl_listener` return `nil` now for localhost addresses and it was getting added to the `@listeners`. - Later on the file descriptor `nil` was getting converted to 0 and resulting into `BadFileDescriptor` error as per this gist - https://gist.github.com/prathamesh-sonpatki/bc0cac8929dbf17316e8b4b7dda93e20. - This issue is now fixed and added test case. - This fixes `rails restart` command on Rails 5 + Puma 3.5 and above. * Test localhost ssl:// as well * Skip tests related to localhost binding on JRuby - Added a helper for omitting tests on JRuby.
This commit is contained in:
parent
8509829729
commit
78b4ab0196
3 changed files with 44 additions and 2 deletions
|
@ -105,7 +105,7 @@ module Puma
|
|||
io = add_tcp_listener uri.host, uri.port, opt, bak
|
||||
end
|
||||
|
||||
@listeners << [str, io]
|
||||
@listeners << [str, io] if io
|
||||
when "unix"
|
||||
path = "#{uri.host}#{uri.path}".gsub("%20", " ")
|
||||
|
||||
|
@ -209,7 +209,7 @@ module Puma
|
|||
io = add_ssl_listener uri.host, uri.port, ctx
|
||||
end
|
||||
|
||||
@listeners << [str, io]
|
||||
@listeners << [str, io] if io
|
||||
else
|
||||
logger.error "Invalid URI: #{str}"
|
||||
end
|
||||
|
|
34
test/test_binder.rb
Normal file
34
test/test_binder.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
require "rbconfig"
|
||||
require 'test/unit'
|
||||
require 'testhelp'
|
||||
|
||||
require 'puma/binder'
|
||||
require 'puma/events'
|
||||
|
||||
class TestBinder < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
@events = Puma::Events.new(STDOUT, STDERR)
|
||||
@binder = Puma::Binder.new(@events)
|
||||
end
|
||||
|
||||
def test_localhost_addresses_dont_alter_listeners_for_tcp_addresses
|
||||
omit_on_jruby
|
||||
|
||||
@binder.parse(["tcp://localhost:10001"], @events)
|
||||
|
||||
assert_equal [], @binder.listeners
|
||||
end
|
||||
|
||||
def test_localhost_addresses_dont_alter_listeners_for_ssl_addresses
|
||||
omit_on_jruby
|
||||
|
||||
key = File.expand_path "../../examples/puma/puma_keypair.pem", __FILE__
|
||||
cert = File.expand_path "../../examples/puma/cert_puma.pem", __FILE__
|
||||
|
||||
@binder.parse(["ssl://localhost:10002?key=#{key}&cert=#{cert}"], @events)
|
||||
|
||||
assert_equal [], @binder.listeners
|
||||
end
|
||||
|
||||
end
|
|
@ -9,6 +9,7 @@ require 'uri'
|
|||
require 'stringio'
|
||||
|
||||
require 'puma'
|
||||
require 'puma/detect'
|
||||
|
||||
# Either takes a string to do a get request against, or a tuple of [URI, HTTP] where
|
||||
# HTTP is some kind of Net::HTTP request object (POST, HEAD, etc.)
|
||||
|
@ -41,3 +42,10 @@ module TimeoutEveryTestCase
|
|||
end
|
||||
end
|
||||
Test::Unit::TestCase.prepend TimeoutEveryTestCase
|
||||
|
||||
module OmitTestsBasedOnRubyEngine
|
||||
def omit_on_jruby
|
||||
omit "Omitted on JRuby" if Puma.jruby?
|
||||
end
|
||||
end
|
||||
Test::Unit::TestCase.prepend OmitTestsBasedOnRubyEngine
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue