1.2.1: Fix connection leak for invocations outside of Rails executor
Fixed
-
Connection leak from the connection pool when
after_commit
called outside Rails executor without connection checked outUsually all invocations of
after_commit
(whether it happens during serving HTTP request in Rails controller or performing job in Sidekiq worker process) are made inside Rails executor which checks in any connections back to the connection pool that were checked out inside its block.However, in cases when a)
after_commit
was called outside of Rails executor (3-rd party gems or non-Rails apps using ActiveRecord) and b) database connection hasn't been checked out yet, then connection will be checked out byafter_commit
implicitly by call toActiveRecord::Base.connection
and not checked in back afterwards causing it to leak from the connection pool.But in that case we can be sure that there is no transaction in progress ('cause one need to checkout connection and issue
BEGIN
to it), so we don't need to check it out at all and can fast-forward towithout_tx
action.See discussion at issue #20 for details.
Pull request #21 by [@Envek][].