Skip to content

Commit 440f289

Browse files
mlarrazclaude
andcommitted
Fix stale worker after refork: remove phase bump from mold_and_refork!
The phase bump on the mold candidate in mold_and_refork! had two compounding bugs: 1. promote_mold filters by `w.phase == @phase`, so the bumped worker was excluded from selection — a different worker got promoted instead 2. After start_phased_restart increments @phase, the bumped worker's phase matched the new @phase, so check_workers skipped it — leaving one worker un-restarted with stale process state Without the phase bump, promote_mold naturally selects the most experienced worker (same one mold_and_refork! would have chosen), and all workers are properly restarted during the phased refork. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7b0c721 commit 440f289

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

lib/puma/cluster.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,8 @@ def most_experienced_worker(workers = @workers)
322322
workers.max { |a, b| a.last_status[:requests_count].to_i <=> b.last_status[:requests_count].to_i }
323323
end
324324

325-
def mold_and_refork!(mold_candidate = most_experienced_worker)
325+
def mold_and_refork!
326326
@mold&.term
327-
mold_candidate.phase = @phase + 1 # cluster phase will catch up next loop; we want this one to be picked as a mold
328327
phased_restart(:refork)
329328
end
330329

@@ -370,7 +369,7 @@ def setup_signals
370369
# wait before kicking off yet another phased restart
371370

372371
current_interval_index += 1
373-
mold_and_refork!(w)
372+
mold_and_refork!
374373
end
375374
end
376375

0 commit comments

Comments
 (0)