Module: Sidekiq::Fiber::ConnectionPoolPatch

Defined in:
lib/sidekiq/fiber/connection_pool_patch.rb

Overview

Patches ActiveRecord’s connection pool to use Fiber.current as the cache key instead of Thread.current.

Without this patch, all fibers on the same thread share one connection slot — causing either connection sharing (data corruption) or unbounded connection checkout (one per fiber).

With this patch, each fiber gets its own connection slot. The developer must still bound fiber concurrency via fiber_concurrency config to avoid exhausting the database connection limit.

Only applied when ActiveRecord is present.

Instance Method Summary collapse

Instance Method Details

#connection_cache_key(_thread) ⇒ Object



16
17
18
# File 'lib/sidekiq/fiber/connection_pool_patch.rb', line 16

def connection_cache_key(_thread)
  ::Fiber.current
end