MagicStack / MagicStack/asyncpg
Application Flow Stuck Unless Connection is Explicitly Closed
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 8.1k
- Fork
- 468
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
- 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
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với ví dụ asyncpg 0.30.0 được cung cấp và tái hiện nó trên Python 3.11, PostgreSQL 16 và Windows, trước tiên xác nhận xem vấn đề có xảy ra với một cài đặt PostgreSQL cục bộ hay không. Điều tra hành vi của trình quản lý ngữ cảnh bất đồng bộ xung quanh self.get_connection() và so sánh với trường hợp gọi conn.close() một cách tường minh; được coi là hoàn tất khi luồng thực thi hoàn thành mà không yêu cầu thao tác đóng tường minh đó.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- postgresql, python
- Lĩnh vực
- backend, databases
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100