Commit 6309f45
fix(active_job): don't clone hub when thread already has one
When a job runs inline inside a Rack request (e.g. ActiveStorage::AnalyzeJob
with perform_enqueued_jobs = true in tests, or inline adapter), the rack
thread already has a hub cloned by CaptureExceptions. Unconditionally
calling clone_hub_to_current_thread on any non-main thread replaced that
hub with a fresh clone of the main hub, wiping out the request transaction.
Downstream instrumentation then called methods on nil and Rails returned 500.
This manifested as a flaky failure on JRuby (where rack threads are real OS
threads, never Thread.main) but not on CRuby (where rack-test runs on the
main thread, so the Thread.current != Thread.main guard fires differently).
Fix: only clone when the thread doesn't already have a hub. This preserves
the lazy-init behaviour for genuine new worker threads (which have no hub
yet) without destroying the hub of threads that were already set up by the
Rack middleware.
Co-Authored-By: github-copilot <noreply@example.com>1 parent 58f8913 commit 6309f45
1 file changed
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
102 | 109 | | |
103 | 110 | | |
104 | 111 | | |
| |||
0 commit comments