diff --git a/CHANGELOG.md b/CHANGELOG.md index fe8a8af6..61252192 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fix `TTIN` during a graceful shutdown spawning new workers. - Prevent `USR1` from restarting the monitor during a graceful shutdown. - Honor shutdown signals while the server is starting. +- Fix `max_consecutive_spawn_errors` counting a timed out spawn twice. - Preserve worker spawn deadlines when the mold starts workers. # 0.18.4 diff --git a/lib/pitchfork/http_server.rb b/lib/pitchfork/http_server.rb index 9c5d8bc0..55220857 100644 --- a/lib/pitchfork/http_server.rb +++ b/lib/pitchfork/http_server.rb @@ -617,9 +617,8 @@ def murder_lazy_workers end def hard_timeout(child) - @consecutive_spawn_errors += 1 unless child.ready? - if child.pid.nil? # Not yet registered, likely never spawned + @consecutive_spawn_errors += 1 logger.error "#{child.to_log} timed out during spawn, abandoning" @children.abandon(child) return diff --git a/test/integration/test_boot.rb b/test/integration/test_boot.rb index c30db58f..e7d62b12 100644 --- a/test/integration/test_boot.rb +++ b/test/integration/test_boot.rb @@ -117,7 +117,7 @@ def test_max_consecutive_spawn_timeout pid = spawn_server(app: APP, config: <<~RUBY) listen "#{addr}:#{port}" worker_processes 3 - max_consecutive_spawn_errors 4 + max_consecutive_spawn_errors 2 spawn_timeout 1 after_worker_fork do |_server, worker| sleep 20 # simulate a stuck worker @@ -128,6 +128,25 @@ def test_max_consecutive_spawn_timeout assert_exited(pid, 1) end + def test_max_consecutive_spawn_timeout_counts_each_timeout_once + addr, port = unused_port + + pid = spawn_server(app: APP, config: <<~RUBY) + listen "#{addr}:#{port}" + worker_processes 1 + max_consecutive_spawn_errors 1 + spawn_timeout 1 + after_worker_fork do |_server, worker| + sleep 20 + end + RUBY + + assert_stderr(/consecutive failures to spawn children, aborting/, timeout: 6) + assert_exited(pid, 1) + before_abort = read_stderr.split("consecutive failures to spawn children, aborting").first + assert_equal 2, before_abort.scan(/worker=0 gen=0.0 pid=\d+ timed out, killing/).size + end + def test_max_consecutive_spawn_errors addr, port = unused_port