MagicStack / MagicStack/asyncpg

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

オープン
#1,268 コメント 0 件 リアクション 4 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
8.1k
フォーク
468
PR マージ指標
30日以内にマージされた PR はありません

説明

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_.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

asyncpg.create_pool から始め、アイドル接続が閉じられるときに max_inactive_connection_lifetime が min_size とどのように作用するかを調べます。提供された sleep と pool.get_size() のチェックを使って問題を再現します。min_size を設定した pool が、アイドル接続のタイムアウト後もその最小数を維持または再取得できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
postgresql, python
領域
databases
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。