Skip to content

Commit

Permalink
Merge branch 'master' into log_formatter_config
Browse files Browse the repository at this point in the history
  • Loading branch information
ylecuyer committed Jun 10, 2019
2 parents ab15a70 + 60f70cd commit 8be0b65
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
@@ -1,6 +1,6 @@
AllCops:
DisabledByDefault: true
TargetRubyVersion: 2.2
TargetRubyVersion: 2.5
DisplayCopNames: true
StyleGuideCopsOnly: false
Exclude:
Expand Down
9 changes: 1 addition & 8 deletions .travis.yml
Expand Up @@ -8,8 +8,7 @@ before_install:
r_eng="$(ruby -e 'STDOUT.write RUBY_ENGINE')";
rv="$(ruby -e 'STDOUT.write RUBY_VERSION')";
if [ "$r_eng" == "ruby" ]; then
if [ "$rv" \< "2.3" ]; then gem update --system 2.7.9 --no-document
elif [ "$rv" \< "2.6" ]; then gem update --system --no-document --conservative
if [ "$rv" \< "2.6" ]; then gem update --system --no-document --conservative
fi
fi
if [ "$TRAVIS_OS_NAME" == "osx" ]; then
Expand All @@ -25,9 +24,6 @@ script:
- bundle exec rake

rvm:
- 2.2.10
- 2.3.8
- 2.4.6
- 2.5.5
- 2.6.3
- ruby-head
Expand All @@ -37,9 +33,6 @@ matrix:
include:
- rvm: ruby-head
env: RUBYOPT="--jit"
- rvm: 2.4.6
os: osx
osx_image: xcode10.2
- rvm: 2.5.5
os: osx
osx_image: xcode10.2
Expand Down
8 changes: 6 additions & 2 deletions History.md
Expand Up @@ -8,15 +8,19 @@
* Min worker timeout (#1716)
* Add option to suppress SignalException on SIGTERM (#1690)
* Allow mutual TLS CA to be set using `ssl_bind` DSL (#1689)
* Reactor now uses nio4r instead of `select` (#1728)
* Minimum Ruby version now >= 2.5 (#1813)
* Add log_formatter configuration
* x bugfixes
* Do not accept new requests on shutdown (#1685)
* Do not accept new requests on shutdown (#1685, #1808)
* Fix 3 corner cases when request body is chunked (#1508)
* Change pid existence check's condition branches (#1650)
* Don't call .stop on a server that doesn't exist (#1655)
* Implemented NID_X9_62_prime256v1 (P-256) curve over P-521 (#1671)
* Fix @notify.close can't modify frozen IOError (RuntimeError) (#1583)

* Fix Java 8 support (#1773)
* Fix error `uninitialized constant Puma::Cluster` (#1731)
* Fix `not_token` being able to be set to true (#1803)

## 3.12.1 / 2019-03-19

Expand Down
4 changes: 2 additions & 2 deletions lib/puma/binder.rb
Expand Up @@ -63,7 +63,7 @@ def import_from_env
remove = []

ENV.each do |k,v|
if k =~ /PUMA_INHERIT_\d+/
if /PUMA_INHERIT_\d+/.match?(k)
fd, url = v.split(":", 2)
@inherited_fds[url] = fd.to_i
remove << k
Expand All @@ -75,7 +75,7 @@ def import_from_env
key = [ :unix, Socket.unpack_sockaddr_un(sock.getsockname) ]
rescue ArgumentError
port, addr = Socket.unpack_sockaddr_in(sock.getsockname)
if addr =~ /\:/
if /\:/.match?(addr)
addr = "[#{addr}]"
end
key = [ :tcp, addr, port ]
Expand Down
20 changes: 16 additions & 4 deletions lib/puma/cluster.rb
Expand Up @@ -36,16 +36,26 @@ def stop_workers

begin
if RUBY_VERSION < '2.6'
@workers.each { |w| Process.waitpid(w.pid) }
@workers.each do |w|
begin
Process.waitpid(w.pid)
rescue Errno::ECHILD
# child is already terminated
end
end
else
# below code is for a bug in Ruby 2.6+, above waitpid call hangs
t_st = Process.clock_gettime(Process::CLOCK_MONOTONIC)
pids = @workers.map(&:pid)
loop do
pids.reject! do |w_pid|
if Process.waitpid(w_pid, Process::WNOHANG)
log " worker status: #{$?}"
true
begin
if Process.waitpid(w_pid, Process::WNOHANG)
log " worker status: #{$?}"
true
end
rescue Errno::ECHILD
true # child is already terminated
end
end
break if pids.empty?
Expand Down Expand Up @@ -401,6 +411,8 @@ def setup_signals
log "Early termination of worker"
exit! 0
else
@launcher.close_binder_listeners

stop_workers
stop

Expand Down
2 changes: 1 addition & 1 deletion lib/puma/configuration.rb
Expand Up @@ -348,7 +348,7 @@ def self.random_token
end

if bytes
token = "".dup
token = +""
bytes.each_byte { |b| token << b.to_s(16) }
else
token = (0..count).to_a.map { rand(255).to_s(16) }.join
Expand Down
19 changes: 9 additions & 10 deletions lib/puma/launcher.rb
Expand Up @@ -216,6 +216,15 @@ def restart_args
end
end

def close_binder_listeners
@binder.listeners.each do |l, io|
io.close
uri = URI.parse(l)
next unless uri.scheme == 'unix'
File.unlink("#{uri.host}#{uri.path}")
end
end

private

def reload_worker_directory
Expand Down Expand Up @@ -321,16 +330,6 @@ def prune_bundler?
@options[:prune_bundler] && clustered? && !@options[:preload_app]
end

def close_binder_listeners
@binder.listeners.each do |l, io|
io.close
uri = URI.parse(l)
next unless uri.scheme == 'unix'
File.unlink("#{uri.host}#{uri.path}")
end
end


def generate_restart_data
if dir = @options[:directory]
@restart_dir = dir
Expand Down
2 changes: 1 addition & 1 deletion lib/puma/server.rb
Expand Up @@ -105,7 +105,7 @@ def tcp_mode!
# On Linux, use TCP_CORK to better control how the TCP stack
# packetizes our stream. This improves both latency and throughput.
#
if RUBY_PLATFORM =~ /linux/
if RUBY_PLATFORM.match?(/linux/)
UNPACK_TCP_STATE_FROM_TCP_INFO = "C".freeze

# 6 == Socket::IPPROTO_TCP
Expand Down
5 changes: 4 additions & 1 deletion puma.gemspec
Expand Up @@ -17,5 +17,8 @@ Gem::Specification.new do |s|
%w[History.md LICENSE README.md]
s.homepage = "http://puma.io"
s.license = "BSD-3-Clause"
s.required_ruby_version = Gem::Requirement.new(">= 2.2")

# We will guarantee to support the last 2 major releases,
# and may choose to support further back as we see fit.
s.required_ruby_version = Gem::Requirement.new(">= 2.5")
end
4 changes: 4 additions & 0 deletions test/rackup/1second.ru
@@ -0,0 +1,4 @@
run lambda { |env|
sleep 1
[200, {}, ["Hello World"]]
}
2 changes: 1 addition & 1 deletion test/shell/t1.rb
Expand Up @@ -11,7 +11,7 @@
File.unlink "t1-stdout" if File.file? "t1-stdout"
File.unlink "t1-pid" if File.file? "t1-pid"

if log =~ %r!GET / HTTP/1\.1!
if %r!GET / HTTP/1\.1!.match?(log)
exit 0
else
exit 1
Expand Down
54 changes: 53 additions & 1 deletion test/test_integration.rb
Expand Up @@ -186,7 +186,7 @@ def test_phased_restart_via_pumactl
until done
@events.stdout.rewind
log = @events.stdout.readlines.join("")
if log =~ /- Worker \d \(pid: \d+\) booted, phase: 1/
if /- Worker \d \(pid: \d+\) booted, phase: 1/.match?(log)
assert_match(/TERM sent/, log)
assert_match(/- Worker \d \(pid: \d+\) booted, phase: 1/, log)
done = true
Expand Down Expand Up @@ -232,6 +232,58 @@ def test_restart_closes_keepalive_sockets_workers
assert_equal "Hello World", new_reply
end

def test_sigterm_closes_listeners_on_forked_servers
skip NO_FORK_MSG unless HAS_FORK
pid = start_forked_server("-w 2 -q test/rackup/1second.ru")
threads = []
initial_reply = nil
next_replies = []
condition_variable = ConditionVariable.new
mutex = Mutex.new

threads << Thread.new do
s = connect
mutex.synchronize { condition_variable.broadcast }
initial_reply = read_body(s)
end

threads << Thread.new do
mutex.synchronize {
condition_variable.wait(mutex, 1)
Process.kill("SIGTERM", pid)
}
end

10.times.each do |i|
threads << Thread.new do
mutex.synchronize { condition_variable.wait(mutex, 1.5) }

begin
s = connect
read_body(s)
next_replies << :success
rescue Errno::ECONNRESET
# connection was accepted but then closed
# client would see an empty response
next_replies << :connection_reset
rescue Errno::ECONNREFUSED
# connection was was never accepted
# it can therefore be re-tried before the
# client receives an empty reponse
next_replies << :connection_refused
end
end
end

threads.map(&:join)

assert_equal "Hello World", initial_reply

assert_includes next_replies, :connection_refused

refute_includes next_replies, :connection_reset
end

# It does not share environments between multiple generations, which would break Dotenv
def test_restart_restores_environment
# jruby has a bug where setting `nil` into the ENV or `delete` do not change the
Expand Down
2 changes: 1 addition & 1 deletion test/test_persistent.rb
Expand Up @@ -37,7 +37,7 @@ def teardown
end

def lines(count, s=@client)
str = "".dup
str = +""
Timeout.timeout(5) do
count.times { str << s.gets }
end
Expand Down
2 changes: 1 addition & 1 deletion win_gem_test/puma.ps1
Expand Up @@ -13,7 +13,7 @@ Make-Const repo_name 'puma'
Make-Const url_repo 'https://github.com/puma/puma.git'

#———————————————————————————————————————————————————————————————— lowest ruby version
Make-Const ruby_vers_low 22
Make-Const ruby_vers_low 25
# null = don't compile; false = compile, ignore test (allow failure);
# true = compile & test
Make-Const trunk $false ; Make-Const trunk_x64 $false
Expand Down

0 comments on commit 8be0b65

Please sign in to comment.