MagicStack / MagicStack/asyncpg

TimeoutError on multiple requests

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

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

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

説明

  • asyncpg version: 0.27.0
  • PostgreSQL version: 14.7
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    : We can reproduce it, not locally
  • Python version: 3.10.2
  • Platform: Backend: Linux, t3large AWS instance, Database: AWS RDS
  • Do you use pgbouncer?: No
  • Did you install asyncpg with pip?: Yes

We're using FastAPI ,and our current code for setting up the db connection is:

connection_arguments: Dict[str, Any] = {"server_settings": {"jit": "off"}}

ENUM_TYPES = (
    ("public", "sometype"), ...
)

async def register_enum_types(conn) -> None: 
    for enum_class, typename in ENUM_TYPES:
        await conn.set_builtin_type_codec(
            typename, schema=enum_class, codec_name="text"
        )


engine = create_async_engine(
    settings.uri,
    echo=False,
    connect_args=connection_arguments,
    pool_size=200,
    max_overflow=10,
)

async_sessionmaker = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)


@event.listens_for(engine.sync_engine, "connect")
def on_connect(dbapi_connection, connection_record):
    dbapi_connection.run_async(register_enum_types)

We added the register_enum_types as we were thinking that the query:
SELECT t.oid, t.typelem AS elemtype, t.typtype AS kind FROM pg_catalog.pg_type AS t WHERE t.oid = $1

which we saw a lot in AWS RDS monitoring is causing the issue, but now we're not sure what is it anymore.

In logs when it happens we see:

File "/path/to/file/python3.10/site-packages/asyncpg/connect_utils.py", line 780, in _connect_addr raise asyncio.TimeoutError asyncio.exceptions.TimeoutError

and after some time, it gets back to normal.

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

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

はじめの一歩

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

調査の方向性

asyncpg/connect_utils.py:780 から始め、報告された asyncio.TimeoutError が発生している箇所を確認し、FastAPI、SQLAlchemy のプーリング、AWS RDS を使用した接続セットアップを調査してください。タイムアウトのログを、同時実行されるプールの設定および報告された pg_catalog クエリと比較してください。再現可能な原因と検証済みの修正、または明確な診断を確立できれば完了です。

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

評価

技術スタック
fastapi, postgresql, python
領域
backend, databases
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
28/100

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

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