MagicStack / MagicStack/asyncpg
A weird log line from the asyncio default exception handler: "Resetting connection with an active transaction"
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 8.1k
- フォーク
- 468
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Sometimes our production component logs the following error
21:05:49.897964000 [Error ] [asyncio] Resetting connection with an active transaction <asyncpg.connection.Connection object at 0x7fb1502561f8>
We create a connection pool first.
Then we use async_timeout, prepared statements, explicit transaction and a cursor to get data.
A coroutine that has this logic may be cancelled sometimes, and this is when we may see the error above. However not every
cancellation produces the error. Cancellation happens oftens but we see this error extremely rarely. I wasn't able to build a
minimal example to reproduce it.
We use a connection pool.
Later, in a different coroutine, we use async_timeout, prepared statements, explicit transaction and a cursor.
A coroutine that has this logic may be cancelled sometimes, and this is when we may see the error above. However not every
cancellation produces the error. Cancellation happens oftens but we see this error extremely rarely. I wasn't able to build a
minimal example to reproduce it.
`
pool = await asyncpg.create_pool(...)
async with async_timeout.timeout(global_delay_sec) as cm:
async with pool.acquire() as conn:
stmt = await conn.prepare(sql)
columns = stmt.get_attributes()
...
async with conn.transaction():
cursor = await stmt.cursor()
raw_values = await cursor.fetch(max_rows + 1)
if len(raw_values) == max_rows + 1:
raise Exception(f"A total number of rows exceeded the allowed maximum of {max_rows} rows")
`
-
asyncpg version:
0.20.1 -
PostgreSQL version:
Reproduced with both postgres-11 and 12 -
Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?:
No we don't use PostgreSQL SaaS
I wasn't able to reproce it the issue locally. -
Python version:
3.6.3 -
Platform:
lsb_release -d
Description: CentOS Linux release 7.6.1810 (Core) -
Do you use pgbouncer?:
no -
Did you install asyncpg with pip?:
yes -
If you built asyncpg locally, which version of Cython did you use?:
We do not build it locally -
Can the issue be reproduced under both asyncio and
uvloop?:
I do use uvloop, I couldn't reproduce it locally. It seems to be an extremely rare issue, happens in our production only once in a month
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
報告されている pool.acquire、prepared-statement、明示的トランザクション、カーソル、async_timeout のフローから始め、示されている操作中のキャンセルに焦点を当てます。記載されている PostgreSQL のバージョンを使って asyncio と uvloop での挙動を比較し、本番環境でのみ発生するログを説明すべき症状として使用します。まれな reset を再現するか、確認済みの原因と解決策を確立できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- postgresql, python
- 領域
- databases
- issue の種類
- バグ
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100