mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
648da12519
Before #34953, when using the `:async` Active Job queue adapter, jobs enqueued in `db/seeds.rb`, such as Active Storage analysis jobs, would cause a hang (see #34939). Therefore, #34953 changed all jobs enqueued in `db/seeds.rb` to use the `:inline` queue adapter instead. (This behavior was later limited to only take effect when the `:async` adapter was configured, see #35905.) However, inline jobs in `db/seeds.rb` cleared `CurrentAttributes` values (see #37526). Therefore, #37568 changed the `:inline` adapter to wrap each job in its own thread, for isolation. However, wrapping a job in its own thread affects which database connection it uses. Thus inline jobs can no longer execute within the calling thread's database transaction, including seeing any uncommitted changes. Additionally, if the calling thread is not wrapped with the executor, the inline job thread (which is wrapped with the executor) can deadlock on the load interlock. And when testing (with `connection_pool.lock_thread = true`), the inline job thread can deadlock on one of the locks added by #28083. Therefore, this commit reverts the solutions of #34953 and #37568, and instead wraps evaluation of `db/seeds.rb` with the executor. This eliminates the original hang from #34939, which was also due to running multiple threads and not wrapping all of them with the executor. And, because nested calls to `executor.wrap` are ignored, any inline jobs in `db/seeds.rb` will not clear `CurrentAttributes` values. Alternative fix for #34939. Reverts #34953. Reverts #35905. Partially reverts #35896. Alternative fix for #37526. Reverts #37568. Fixes #40552. |
||
---|---|---|
.. | ||
active_job | ||
rails/generators/job | ||
active_job.rb |