Skip to content

Commit

Permalink
cluster.rb - no zombies (#1887)
Browse files Browse the repository at this point in the history
* cluster.rb - fixup for Cluster#check_workers, removes zombies?

* test_integration.rb - add zombie test

Co-authored-by: Matt Duszynski <mattduszynski@gmail.com>

* travis.yml - misc updates

jruby-head to bionic
xcode10.2 to xcode11
all ruby 2.2 to 2.2.10
  • Loading branch information
MSP-Greg authored and nateberkopec committed Aug 6, 2019
1 parent be13b96 commit b32de94
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
18 changes: 11 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,36 @@ rvm:
matrix:
fast_finish: true
include:
- rvm: 2.2
dist: trusty
- rvm: 2.2.10
dist: trusty
env: OS="Trusty 14.04 OpenSSL 1.0.1"
- rvm: 2.6
- rvm: 2.6.3
dist: bionic
env: OS="Bionic 18.04 OpenSSL 1.1.1"
- rvm: ruby-head
env: jit=yes
- rvm: 2.4.6
os: osx
osx_image: xcode10.2
env: OS="osx xcode10.2"
osx_image: xcode11
env: OS="osx xcode11"
- rvm: 2.5.5
os: osx
osx_image: xcode10.2
env: OS="osx xcode10.2"
osx_image: xcode11
env: OS="osx xcode11"
- rvm: jruby-9.2.7.0
env: JRUBY_OPTS="--debug" JAVA_OPTS="--add-opens java.base/sun.nio.ch=org.jruby.dist --add-opens java.base/java.io=org.jruby.dist --add-opens java.base/java.util.zip=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.security.cert=ALL-UNNAMED --add-opens java.base/java.security=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED"
- rvm: jruby-head
dist: bionic
env: OS="Bionic 18.04"

allow_failures:
- rvm: ruby-head
- rvm: ruby-head
env: jit=yes
- rvm: jruby-9.2.7.0
- rvm: jruby-head
dist: bionic
env: OS="Bionic 18.04"

env:
global:
Expand Down
8 changes: 5 additions & 3 deletions lib/puma/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,11 @@ def check_workers(force=false)
# during this loop by giving the kernel time to kill them.
sleep 1 if any

@workers.reject! { |w| Process.waitpid(w.pid, Process::WNOHANG) }

@workers.reject!(&:dead?)
pids = []
while pid = Process.waitpid(-1, Process::WNOHANG) do
pids << pid
end
@workers.reject! { |w| w.dead? || pids.include?(w.pid) }

cull_workers
spawn_workers
Expand Down
18 changes: 18 additions & 0 deletions test/test_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,22 @@ def test_not_accepts_new_connections_after_term_signal
Process.wait(@server.pid)
@server = nil # prevent `#teardown` from killing already killed server
end

def test_no_zombie_children
skip NO_FORK_MSG unless HAS_FORK

worker_pids = []
server = server("-w 2 test/rackup/hello.ru")
# Get the PIDs of the child workers.
while worker_pids.size < 2
next unless line = server.gets.match(/pid: (\d+)/)
worker_pids << line.captures.first.to_i
end
# Signal the workers to terminate, and wait for them to die.
worker_pids.each { |pid| Process.kill :TERM, pid }
sleep 2

# Should return nil if Puma has correctly cleaned up
assert_nil Process.waitpid(-1, Process::WNOHANG)
end
end

0 comments on commit b32de94

Please sign in to comment.