Puma plugin in async mode: jobs that finish while Puma stops go back to the queue
維護者通常 4 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 72/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
研究方向
閱讀 test/integration/puma/plugin_testing.rb 中的 Puma 外掛程式生命週期,以及 issue 中描述的 AsyncSupervisor 關閉回呼。使用 TARGET_DB=sqlite bin/rails test test/integration/puma/plugin_stop_repro_test.rb 執行提供的重現;在 async 模式下應該會通過。issue 也將 test/integration/async_processes_lifecycle_test.rb 和 Puma 外掛程式測試列為迴歸檢查。
由索引模型根據 Issue 內容生成。
描述
With solid_queue_mode :async, stopping Puma while a job runs lets the job finish. But the job isn't recorded as finished: it goes back to its queue and runs again, either on the next start or, sometimes, right away before the process exits. This happens even when the job finishes well within shutdown_timeout, so it isn't the timeout case that #815 handles.
Reproduction
On main (b9c646a, 1.7.2, which includes #815). This is a test in the style of the existing plugin tests (test/integration/puma/plugin_testing.rb):
# test/integration/puma/plugin_stop_repro_test.rb
require "test_helper"
require_relative "plugin_testing"
ENV["SOLID_QUEUE_SKIP_RECURRING"] = "true"
class PluginAsyncStopReproTest < ActiveSupport::TestCase
include PluginTesting
test "a job finishing within the shutdown timeout while puma stops is recorded as finished" do
active_job = StoreResultJob.perform_later(:stop, pause: 1.second)
job = SolidQueue::Job.find_by!(active_job_id: active_job.job_id)
wait_while_with_timeout(5.seconds) { skip_active_record_query_cache { job.reload.claimed_execution.nil? } }
terminate_process(@pid, signal: :TERM)
skip_active_record_query_cache do
assert_equal 1, JobResult.where(value: :stop, status: "completed").count
assert job.reload.finished?
assert_nil job.ready_execution
end
end
private
def solid_queue_mode = :async
end
TARGET_DB=sqlite bin/rails test test/integration/puma/plugin_stop_repro_test.rb fails in 5 of 5 runs, and the same with TARGET_DB=mysql and TARGET_DB=postgres. Each run ends one of two ways:
finished=0 ready=1: the job ran once but is back in the queue; or- two completed
JobResults: it ran twice before Puma exited.
The same test with solid_queue_mode :fork passes every time. The test dummy's shutdown_timeout is 2 seconds; the job takes 1.
Cause
When Puma stops, the plugin calls stop on the embedded AsyncSupervisor, whose run loop then runs the shutdown callbacks. after_shutdown callbacks run in the order they were defined:
Registrable's:deregistercomes first. Deregistering the supervisor also deregisters its supervisees, which releases the workers' claimed executions while their jobs are still running.AsyncSupervisor'safter_shutdown :terminate_gracefully, unless: :standalone?comes after it, and only then waits for the threads.
By the time a job finishes, its claimed execution is gone. So the job's finished transaction doesn't record it, and the job is already back in the ready list, where a worker thread that hasn't stopped polling yet can claim it again.
The standalone async supervisor (bin/jobs --mode async) isn't affected: on TERM or INT, its signal handling calls terminate_gracefully before shutdown.
Possible fix
Wait for the threads before deregistering. One line:
- after_shutdown :terminate_gracefully, unless: :standalone?
+ before_shutdown :terminate_gracefully, unless: :standalone?
With that change, the reproduction passes 5 of 5 times on each of the three databases. test/integration/async_processes_lifecycle_test.rb and the Puma plugin tests pass too, locally. Happy to open a PR with the test.
- 主要語言
- Ruby
- 星號
- 2.5k
- 分支
- 271
- 平均合併
- 5 天 6 小時
- 30 天內合併 PR
- 5
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 提供 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 沒有貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
rails/solid_queue 的其他 Issue
-
難度 5/5 一週以上 新手友好度 45/100
rails/solid_queue#836 ·
維護者通常 4 天內回覆
-
難度 5/5 一週以上 新手友好度 25/100
rails/solid_queue#834 · 1 則留言 ·
維護者通常 4 天內回覆
-
難度 5/5 一週以上 新手友好度 25/100
rails/solid_queue#824 · 1 個 reaction ·
維護者通常 4 天內回覆
-
難度 5/5 一週以上 新手友好度 42/100
rails/solid_queue#808 · 3 則留言 ·
維護者通常 4 天內回覆
-
難度 4/5 3-5 天 新手友好度 45/100
rails/solid_queue#806 ·
維護者通常 4 天內回覆
查看 rails/solid_queue 的全部 Issue
相似的 Issue
-
開発用DockerイメージにPlaywrightのシステム依存を追加する可能已有人在做 @momocus 今天認領。 未關閉
難度 1/5 1 小時以內 新手友好度 85/100
sakazuki-org/sakazuki#1453 ·
維護者通常 3 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
jenkins-infra/jenkins.io#9615 · 1 則留言 ·
維護者通常 1 天內回覆
-
fix(ocr): compile the Tesseract-free pipeline with Tokio runtime可能已有人在做 @Goldziher 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
Metric tooltips that contradict how the metric is calculated可能已有人在做 @aniadeadu 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 72/100
WikiEducationFoundation/WikiEduDashboard#7303 · 1 則留言 ·
維護者通常 1 天內回覆
-
WhatsApp Cloud template sync saves a partial template list when one page of the Graph API response fails可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 2 天內回覆