MagicStack / MagicStack/asyncpg
Pool created with min_size loses inactive connections and never re-acquires them
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.1k
- Forks
- 468
- PR merge metrics
- No merged PRs in 30d
Description
I love `asyncpg`, been using it for years. However recently came across some unexpected behavior with v 0.30.0. It goes a little something like this.
Initialize a pool with a `min_size`:
```python
import asyncio
import asyncpg
pool = await asyncpg.create_pool(min_size=10, max_size=20, **kwargs) # assume kwargs has connection info
print(f'Total: {pool.get_size()}')
# Total: 10
```
All good. But now let's say that nothing happens for over 5 minutes. You know, because `max_inactive_connection_lifetime=300.0` by default. And check again:
```python
await asyncio.sleep(305)
print(f'Total: {pool.get_size()}')
# Total: 0
```
Huh? Why isn't it still 10? No matter what I set for `max_inactive_connection_lifetime` this behavior happens immediately after that time, as long as the time is non-zero. If it's set to `0` then the behavior correctly doesn't happen.
I don't know if this is intentional or not, but as a developer, when I open a database pool with a minimum number of connections I expect that the pool will maintain that minimum, _even if they are automatically closed or timeout_.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at asyncpg.create_pool and inspect how max_inactive_connection_lifetime interacts with min_size when idle connections are closed. Reproduce the issue with the provided sleep and pool.get_size() checks. Done means a pool configured with min_size retains or re-acquires that minimum after inactive connections time out.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100