Skip to content

Pool created with min_size loses inactive connections and never re-acquires them #1268

Description

@bdoms

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:

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:

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions