1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activejob/lib/active_job/queue_adapters
Jonathan Hefner 648da12519 Wrap evaluation of db/seeds.rb with the executor
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.
2020-11-18 16:26:20 -06:00
..
async_adapter.rb [ci skip] Fix link to Concurrent::ThreadPoolExecutor docs 2018-10-11 13:29:34 +02:00
backburner_adapter.rb ActiveJob Backburner adapter: fix priority 2018-09-07 21:55:05 -07:00
delayed_job_adapter.rb Improve DelayedJob wrapper logging 2017-11-24 10:40:16 +01:00
inline_adapter.rb Wrap evaluation of db/seeds.rb with the executor 2020-11-18 16:26:20 -06:00
que_adapter.rb Add support for que name to Que adapter. 2020-03-04 13:50:13 +01:00
queue_classic_adapter.rb [Active Job] rubocop -a --only Layout/EmptyLineAfterMagicComment 2017-07-11 13:12:32 +09:00
resque_adapter.rb [Active Job] rubocop -a --only Layout/EmptyLineAfterMagicComment 2017-07-11 13:12:32 +09:00
sidekiq_adapter.rb Allow Sidekiq access to the underlying Job class 2019-09-16 10:17:14 -07:00
sneakers_adapter.rb [Active Job] rubocop -a --only Layout/EmptyLineAfterMagicComment 2017-07-11 13:12:32 +09:00
sucker_punch_adapter.rb [ci skip] switch eg. to proper e.g. 2019-10-07 02:18:36 +02:00
test_adapter.rb Move responsibility of the filtered? back to enqueue methods 2020-03-16 20:49:30 +01:00