You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4e6339c
Browse filesBrowse the repository at this point in the historyBrowse files
Reap a tenant connection pool only once no thread is using it
Reaping a pool to stay under max_connection_pools went through
remove_connection_pool, which disconnects the pool forcibly and takes
a connection away from the thread that has it checked out, even in the
middle of a transaction. The rows that transaction had already written
stayed committed.
A pool is now emptied with ConnectionPool#disconnect, which raises
instead, and removed only while its locks are held and only if the
connection handler still has that same pool. A pool in use is skipped
and reaped by a later lookup once it is idle.
A model's with_connection, lease_connection and connection retry a
checkout that fails because the pool was reaped after they looked it
up, until the pool's checkout_timeout has passed. A model's schema
cache does the same, staying with the tenant and role it was got in.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,10 @@
2
2
3
3
## next / unreleased
4
4
5
+
### Fixed
6
+
7
+
- Reaping a connection pool to stay under `max_connection_pools` no longer takes a connection away from a thread that is using it. Before, a thread in the middle of a transaction could lose its connection after it had written part of the transaction, and the part already written stayed committed. A pool that is in use is now skipped and reaped by a later lookup once it is idle, so `max_connection_pools` can be exceeded while pools are in use. When a pool is reaped between a model's `with_connection`, `lease_connection`, `connection` or `schema_cache` looking it up and using it, the call is retried with the tenant's new pool, for up to the pool's `checkout_timeout`. Code that holds on to a pool object itself, from `connection_pool`, can still raise `ActiveRecord::ConnectionNotEstablished` if that pool is reaped, before any SQL runs, as it could before.
Copy file name to clipboardExpand all lines: GUIDE.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -287,7 +287,7 @@ production:
287
287
max_connection_pools: 20
288
288
```
289
289
290
-
Active Record Tenanted will reap the least-recently-used connection pools when this limit is surpassed. Developers are encouraged to tune this parameter with care, since setting it too low may lead to increased request latency due to frequently re-establishing database connections, while setting it too high may consume precious file descriptors and memory resources.
290
+
Active Record Tenanted will reap the least-recently-used connection pools when this limit is surpassed. A pool that a thread is using is not reaped, because that would take its connection away, possibly in the middle of a transaction. So while more pools than the limit are in use the process holds more pools than the limit, and the extra pools are reaped when a later lookup finds them idle. Nothing reaps them on a schedule. Developers are encouraged to tune this parameter with care, since setting it too low may lead to increased request latency due to frequently re-establishing database connections, while setting it too high may consume precious file descriptors and memory resources.
0 commit comments