mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Assure worker index always within 0...@options[:workers]
This commit is contained in:
parent
b01b43d1da
commit
fdb4d27967
4 changed files with 41 additions and 4 deletions
|
@ -7,7 +7,6 @@ module Puma
|
||||||
|
|
||||||
@phase = 0
|
@phase = 0
|
||||||
@workers = []
|
@workers = []
|
||||||
@worker_index = 0
|
|
||||||
@next_check = nil
|
@next_check = nil
|
||||||
|
|
||||||
@phased_state = :idle
|
@phased_state = :idle
|
||||||
|
@ -99,9 +98,10 @@ module Puma
|
||||||
end
|
end
|
||||||
|
|
||||||
def next_worker_index
|
def next_worker_index
|
||||||
i = @worker_index
|
all_positions = 0...@options[:workers]
|
||||||
@worker_index += 1
|
occupied_positions = @workers.map { |w| w.index }
|
||||||
i
|
available_positions = all_positions.to_a - occupied_positions
|
||||||
|
available_positions.first
|
||||||
end
|
end
|
||||||
|
|
||||||
def all_workers_booted?
|
def all_workers_booted?
|
||||||
|
|
|
@ -14,4 +14,11 @@ else
|
||||||
ERROR=2
|
ERROR=2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ruby -rubygems t3.rb > /dev/null 2>&1; then
|
||||||
|
echo "t3 OK"
|
||||||
|
else
|
||||||
|
echo "t3 FAIL"
|
||||||
|
ERROR=3
|
||||||
|
fi
|
||||||
|
|
||||||
exit $ERROR
|
exit $ERROR
|
||||||
|
|
25
test/shell/t3.rb
Normal file
25
test/shell/t3.rb
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
system "ruby -rubygems -I../../lib ../../bin/puma -p 10102 -C t3_conf.rb ../hello.ru &"
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
worker_pid_was_present = File.file? "t3-worker-2-pid"
|
||||||
|
|
||||||
|
system "kill `cat t3-worker-2-pid`" # kill off a worker
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
worker_index_within_number_of_workers = !File.file?("t3-worker-3-pid")
|
||||||
|
|
||||||
|
system "kill `cat t3-pid`"
|
||||||
|
|
||||||
|
File.unlink "t3-pid" if File.file? "t3-pid"
|
||||||
|
File.unlink "t3-worker-0-pid" if File.file? "t3-worker-0-pid"
|
||||||
|
File.unlink "t3-worker-1-pid" if File.file? "t3-worker-1-pid"
|
||||||
|
File.unlink "t3-worker-2-pid" if File.file? "t3-worker-2-pid"
|
||||||
|
File.unlink "t3-worker-3-pid" if File.file? "t3-worker-3-pid"
|
||||||
|
|
||||||
|
if worker_pid_was_present and worker_index_within_number_of_workers
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
5
test/shell/t3_conf.rb
Normal file
5
test/shell/t3_conf.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
pidfile "t3-pid"
|
||||||
|
workers 3
|
||||||
|
on_worker_boot do |index|
|
||||||
|
File.open("t3-worker-#{index}-pid", "w") { |f| f.puts Process.pid }
|
||||||
|
end
|
Loading…
Reference in a new issue