1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Fix for spawning subprocesses with fork_worker option

This commit is contained in:
Will Jordan 2020-05-15 10:27:37 -07:00
parent 91e57f4e17
commit 2d9b72ecc1
2 changed files with 20 additions and 3 deletions

View file

@ -248,6 +248,7 @@ module Puma
$0 = title
Signal.trap "SIGINT", "IGNORE"
Signal.trap "SIGCHLD", "DEFAULT"
fork_worker = @options[:fork_worker] && index == 0
@ -284,9 +285,11 @@ module Puma
if fork_worker
restart_server.clear
worker_pids = []
Signal.trap "SIGCHLD" do
Process.wait(-1, Process::WNOHANG) rescue nil
wakeup!
wakeup! if worker_pids.reject! do |p|
Process.wait(p, Process::WNOHANG) rescue true
end
end
Thread.new do
@ -303,7 +306,7 @@ module Puma
elsif idx == 0 # restart server
restart_server << true << false
else # fork worker
pid = spawn_worker(idx, master)
worker_pids << pid = spawn_worker(idx, master)
@worker_write << "f#{pid}:#{idx}\n" rescue nil
end
end

View file

@ -168,6 +168,20 @@ RUBY
refute_includes pids, get_worker_pids(1, WORKERS - 1)
end
def test_fork_worker_spawn
cli_server '', config: <<RUBY
workers 1
fork_worker 0
app do |_|
pid = spawn('ls', [:out, :err]=>'/dev/null')
sleep 0.01
exitstatus = Process.detach(pid).value.exitstatus
[200, {}, [exitstatus.to_s]]
end
RUBY
assert_equal '0', read_body(connect)
end
def test_nakayoshi
cli_server "-w #{WORKERS} test/rackup/hello.ru", config: <<RUBY
nakayoshi_fork true