Skip to content

1.2.1: Fix connection leak for invocations outside of Rails executor

Compare
Choose a tag to compare
@github-actions github-actions released this 10 Jun 16:12
v1.2.1
9056d71

Fixed

  • Connection leak from the connection pool when after_commit called outside Rails executor without connection checked out

    Usually 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 by after_commit implicitly by call to ActiveRecord::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 to without_tx action.

    See discussion at issue #20 for details.

    Pull request #21 by [@Envek][].