<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/what-an-active-record-connection-pool-actually-controls-lefxiwsio" -->

---
title: What an Active Record Connection Pool Actually Controls
description: A checkout timeout in Active Record can happen when a thread holds its connection after its query finished, not because SQL is slow. In Rails 8.1.4.1,...
canonical: https://daily.dev/posts/what-an-active-record-connection-pool-actually-controls-lefxiwsio
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: What an Active Record Connection Pool Actually Controls | daily.dev
og:description: A checkout timeout in Active Record can happen when a thread holds its connection after its query finished, not because SQL is slow. In Rails 8.1.4.1,...
og:url: https://daily.dev/posts/what-an-active-record-connection-pool-actually-controls-lefxiwsio
og:image: https://api.daily.dev/og/posts/lefxIwsio.png
og:image:alt: What an Active Record Connection Pool Actually Controls
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# What an Active Record Connection Pool Actually Controls

**[RUBYLAND](https://daily.dev/sources/rubyla)** · 14 min read · 0 upvotes · 0 comments

## Summary

A checkout timeout in Active Record can happen when a thread holds its connection after its query finished, not because SQL is slow. In Rails 8.1.4.1, `pool.stat[:busy]` counts connections owned by live threads, whether or not they are running SQL. Two Ruby threads on a one-connection pool reproduce it: thread A leaves its `with_connection` block before waiting, and thread B then gets the connection. An ordinary `find` leaves `busy=0`, but an outer block, `lease_connection`, or `Base.connection` keeps it at 1. Setting `permanent_connection_checkout = :deprecated` in development flags those `Base.connection` calls.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://railsrevelry.substack.com/p/what-an-active-record-connection-pool-actually-controls>

## Questions this post answers

### Why do I get ActiveRecord::ConnectionTimeoutError when no slow query is running?

The pool's busy count reflects connections owned by live execution contexts, not connections executing SQL. A thread that finished its query but still sits inside a `with_connection` block, or holds a lease, keeps the connection busy. Other threads then wait for checkout and time out. In Active Record 8.1.4.1 this is reproducible with two threads and a one-connection pool.

_Developers shipping Rails apps track connection pool pitfalls like this on daily.dev._

### Does ActiveRecord::Base.connection keep a database connection checked out in Rails 8.1?

Yes. Under default settings in Rails 8.1.4.1, `Base.connection` calls `lease_connection` and can leave the lease in place after a `with_connection` block exits. Passing `prevent_permanent_checkout: true` to a fresh block avoids this. Setting `permanent_connection_checkout` to `:deprecated` in development warns with caller info, and `:disallowed` raises an error.

_Teams hunting down leaked connections in Rails code follow these fixes on daily.dev._

### How can I tell whether a pool timeout needs more connections or shorter connection ownership in Active Record?

A timeout alone cannot tell you. Inspect the pool the failing work actually uses, resolved by connection class, role, and shard. Capture `size`, `connections`, `busy`, `idle`, and `waiting` during the failure, then look for an enclosing connection block or lingering lease. In the demo, narrowing ownership let a second thread succeed without adding connections.

_Engineers deciding between bigger pools and tighter code keep up with Rails internals on daily.dev._

## Similar posts on daily.dev

- [Rails 7.2 Connection Pool Changes May Slow Down Your App](https://daily.dev/posts/rails-7-2-connection-pool-changes-may-slow-down-your-app-lijst2kqn) · RUBYLAND · 0 upvotes · 0 comments
- [Hooking into ActiveRecord’s Connection Pool: A Clean Way to Enable PostgreSQL Row-Level Security](https://daily.dev/posts/hooking-into-activerecord-s-connection-pool-a-clean-way-to-enable-postgresql-row-level-security-n5hxo7tyb) · RUBYLAND · 0 upvotes · 0 comments
- [PostgreSQL Lockup vs Stale Connection: How to Tell Them Apart](https://daily.dev/posts/postgresql-lockup-vs-stale-connection-how-to-tell-them-apart-ctzk0b0lo) · Planet PostgreSQL · 0 upvotes · 0 comments
- [Connection Pool Sizing, Measured: Why 48 Connections Beat 400](https://daily.dev/posts/connection-pool-sizing-measured-why-48-connections-beat-400-f0oqizynp) · The Infinity · 62 upvotes · 5 comments
- [Active Record gets better every week](https://daily.dev/posts/active-record-gets-better-every-week-revvg5fub) · This Week in Rails · 1 upvotes · 0 comments

---

Tags: [#database](https://daily.dev/tags/database), [#ruby](https://daily.dev/tags/ruby), [#rails](https://daily.dev/tags/rails), [#sqlite](https://daily.dev/tags/sqlite)

[View this post on daily.dev](https://daily.dev/posts/what-an-active-record-connection-pool-actually-controls-lefxiwsio)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"What an Active Record Connection Pool Actually Controls","url":"https://daily.dev/posts/what-an-active-record-connection-pool-actually-controls-lefxiwsio","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/what-an-active-record-connection-pool-actually-controls-lefxiwsio"},"datePublished":"2026-11-29T04:27:06.917Z","dateModified":"2026-11-29T04:27:32.909Z","description":"A checkout timeout in Active Record can happen when a thread holds its connection after its query finished, not because SQL is slow. In Rails 8.1.4.1,...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e58779c421c8728df1de52fc11e65a95?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e58779c421c8728df1de52fc11e65a95?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"RUBYLAND","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"RUBYLAND","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/rubyla","url":"https://daily.dev/sources/rubyla"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/what-an-active-record-connection-pool-actually-controls-lefxiwsio","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"database,ruby,rails,sqlite","timeRequired":"PT14M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"RUBYLAND","item":"https://daily.dev/sources/rubyla"},{"@type":"ListItem","position":3,"name":"What an Active Record Connection Pool Actually Controls"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/what-an-active-record-connection-pool-actually-controls-lefxiwsio#faq","mainEntity":[{"@type":"Question","name":"Why do I get ActiveRecord::ConnectionTimeoutError when no slow query is running?","acceptedAnswer":{"@type":"Answer","text":"The pool's busy count reflects connections owned by live execution contexts, not connections executing SQL. A thread that finished its query but still sits inside a `with_connection` block, or holds a lease, keeps the connection busy. Other threads then wait for checkout and time out. In Active Record 8.1.4.1 this is reproducible with two threads and a one-connection pool. Developers shipping Rails apps track connection pool pitfalls like this on daily.dev."}},{"@type":"Question","name":"Does ActiveRecord::Base.connection keep a database connection checked out in Rails 8.1?","acceptedAnswer":{"@type":"Answer","text":"Yes. Under default settings in Rails 8.1.4.1, `Base.connection` calls `lease_connection` and can leave the lease in place after a `with_connection` block exits. Passing `prevent_permanent_checkout: true` to a fresh block avoids this. Setting `permanent_connection_checkout` to `:deprecated` in development warns with caller info, and `:disallowed` raises an error. Teams hunting down leaked connections in Rails code follow these fixes on daily.dev."}},{"@type":"Question","name":"How can I tell whether a pool timeout needs more connections or shorter connection ownership in Active Record?","acceptedAnswer":{"@type":"Answer","text":"A timeout alone cannot tell you. Inspect the pool the failing work actually uses, resolved by connection class, role, and shard. Capture `size`, `connections`, `busy`, `idle`, and `waiting` during the failure, then look for an enclosing connection block or lingering lease. In the demo, narrowing ownership let a second thread succeed without adding connections. Engineers deciding between bigger pools and tighter code keep up with Rails internals on daily.dev."}}]}
```

