Skip to content

Commit 9056d71

Browse files
committed
1.2.1: Fix connection leak for invocations outside of Rails executor
1 parent 6e0faf0 commit 9056d71

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## 1.2.1 (2022-06-10)
8+
9+
### Fixed
10+
11+
- Connection leak from the connection pool when `after_commit` called outside Rails executor without connection checked out
12+
13+
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](https://guides.rubyonrails.org/threading_and_code_execution.html#executor) which checks in any connections back to the connection pool that were checked out inside its block.
14+
15+
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.
16+
17+
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.
18+
19+
See discussion at [issue #20](https://github.com/Envek/after_commit_everywhere/issues/20) for details.
20+
21+
[Pull request #21](https://github.com/Envek/after_commit_everywhere/pull/21) by [@Envek][].
22+
723
## 1.2.0 (2022-03-26)
824

925
### Added
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module AfterCommitEverywhere
4-
VERSION = "1.2.0"
4+
VERSION = "1.2.1"
55
end

0 commit comments

Comments
 (0)