Application Flow Stuck Unless Connection is Explicitly Closed

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

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

評価

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

調査の方向性

提供された asyncpg 0.30.0 の例から始め、Python 3.11、PostgreSQL 16、Windows で再現し、まずローカルの PostgreSQL インストールで問題が発生するか確認します。self.get_connection() 周辺の非同期コンテキストマネージャーの動作を調査し、明示的な conn.close() の場合と比較します。明示的な close を要求せずにフローが完了すれば完了です。

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

説明

  • asyncpg version: 0.30.0
  • PostgreSQL version: 16
  • Do you use a PostgreSQL SaaS? If so, which?: Yes, I am using NeonDB
  • Can you reproduce the issue with a local PostgreSQL install?: Didn't attempt it.
  • Python version: 3.11.0
  • Platform: Windows
  • Do you use pgbouncer?: No
  • Did you install asyncpg with pip?: Yes
  • If you built asyncpg locally, which version of Cython did you use?: [Your Cython version if applicable]
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : [Yes/No] I did not try uvloop

I'm encountering an issue where the flow of my application gets stuck unless the database connection is explicitly closed after a query, even though it should be managed automatically by the context manager.

Code Example:

async def read_record(self, request_details: dict):
    """
    Retrieve records based on conditions and request_type.
    
    Args:
        request_details (dict): The conditions including request_type.
    
    Returns:
        list: The records that match the conditions.
    """
    table = self.get_table_name(request_details['request_type'])
    conditions = {key: request_details[key] for key in request_details if key != 'request_type'}
    condition_str = " AND ".join(f"{key} = ${i+1}" for i, key in enumerate(conditions.keys()))
    query = f"SELECT * FROM {table} WHERE {condition_str};"

    async with self.get_connection() as conn:
        conn.add_log_listener(lambda connection, message: logger.info("PostgreSQL log message: %s", message))
        result = await conn.fetch(query, *conditions.values())
        logger.info("Fetched records: %s", result)
        # await conn.close() # get's stuck without this line

    return result
主要言語
Python
スター
8.1k
フォーク
469
平均マージ
4時間 42分
マージ済み PR(30日)
6

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

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

はじめの一歩

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

MagicStack/asyncpg のほかの issue

MagicStack/asyncpg の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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