MagicStack / MagicStack/asyncpg

ConnectionDoesNotExistError when releasing

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

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

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

説明

  • asyncpg version: 0.21.0
  • PostgreSQL version: 10.7
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    : no
  • Python version: 3.7
  • Platform: debian (docker image python:3.7.9-slim)
  • Do you use pgbouncer?: no
  • Did you install asyncpg with pip?: yes
  • If you built asyncpg locally, which version of Cython did you use?: no
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : only tried asyncio

I've found the following exception in our logs:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/asyncpg/pool.py", line 214, in release
    self._con.terminate()
AttributeError: 'NoneType' object has no attribute 'terminate'

During handling of the above exception, another exception occurred:
File "/usr/local/lib/python3.7/site-packages/my_code_calling_release.py", line 40, in acquire
     await self.pool.release(con)
File "/usr/local/lib/python3.7/site-packages/asyncpg/pool.py", line 654, in release
     return await asyncio.shield(ch.release(timeout))   
File "/usr/local/lib/python3.7/site-packages/asyncpg/pool.py", line 216, in release
     raise ex   
File "/usr/local/lib/python3.7/site-packages/asyncpg/pool.py", line 206, in release
     await self._con.reset(timeout=budget)
File "/usr/local/lib/python3.7/site-packages/asyncpg/connection.py", line 1137, in reset
     await self.execute(reset_query, timeout=timeout)
File "/usr/local/lib/python3.7/site-packages/asyncpg/connection.py", line 295, in execute
     return await self._protocol.query(query, timeout)
File "asyncpg/protocol/protocol.pyx", line 316, in query

From what I can see, the call at self._con.reset is raising a ConnectionDoesNotExistError.
Should the exception be reraised at line 218 if the exception is an ConnectionDoesNotExistError (we know it's already closed)? It shouldn't even try to self._con.terminate() because self._con is already None (see the exception).

Not sure if the comments in that code still apply for that type of exception

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

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

はじめの一歩

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

調査の方向性

asyncpg/pool.py の 206-218 行付近の release パスと、asyncpg/connection.py の reset パスを読み、ConnectionDoesNotExistError によって self._con が None のままになる仕組みに注目してください。すでに閉じられた接続を release する回帰ケースを再現または追加し、その後、release が存在しない接続を終了しようとせず、意図された例外の挙動を維持することを確認してください。

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

評価

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

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

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