mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Ignore multiple port declarations
Right now if you specify a port via `-p $PORT` and via a `config/puma.rb` then puma will incorrectly try to bind to the same port twice and will fail. This PR calls `uniq!` on the array to remove duplicate ports from the `binds` array.
This commit is contained in:
parent
60f9fcf89c
commit
3f2fb13fcd
3 changed files with 30 additions and 0 deletions
|
@ -64,6 +64,8 @@ module Puma
|
|||
unless @options[:tag]
|
||||
@options[:tag] = infer_tag
|
||||
end
|
||||
|
||||
@options[:binds].uniq!
|
||||
end
|
||||
|
||||
def infer_tag
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
port ENV['PORT'] if ENV['PORT']
|
||||
|
||||
app do |env|
|
||||
[200, {}, ["embedded app"]]
|
||||
end
|
||||
|
|
|
@ -14,6 +14,17 @@ class TestConfigFile < Test::Unit::TestCase
|
|||
assert_equal [200, {}, ["embedded app"]], app.call({})
|
||||
end
|
||||
|
||||
def test_double_bind_port
|
||||
port = rand(30_000..40_000).to_s
|
||||
with_env("PORT" => port) do
|
||||
opts = { :binds => ["tcp://#{Configuration::DefaultTCPHost}:#{port}"], :config_file => "test/config/app.rb"}
|
||||
conf = Puma::Configuration.new opts
|
||||
conf.load
|
||||
|
||||
assert_equal ["tcp://0.0.0.0:#{port}"], conf.options[:binds]
|
||||
end
|
||||
end
|
||||
|
||||
def test_lowleve_error_handler_DSL
|
||||
opts = { :config_file => "test/config/app.rb" }
|
||||
conf = Puma::Configuration.new opts
|
||||
|
@ -23,4 +34,19 @@ class TestConfigFile < Test::Unit::TestCase
|
|||
|
||||
assert_equal [200, {}, ["error page"]], app.call({})
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def with_env(env = {})
|
||||
original_env = {}
|
||||
env.each do |k, v|
|
||||
original_env[k] = ENV[k]
|
||||
ENV[k] = v
|
||||
end
|
||||
yield
|
||||
ensure
|
||||
original_env.each do |k, v|
|
||||
ENV[k] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue