MagicStack / MagicStack/asyncpg

LOG: could not receive data from client: Connection reset by peer

Đang mở
#736 2 bình luận 3 reaction 0 người được giao Xem trên GitHub

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.22.0
  • PostgreSQL version: 12
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    : AWS Aurora . Cannot reproduce with a local PostgreSQL.
  • Python version: v3.7.6+
  • Platform:
  • Do you use pgbouncer?: No
  • Did you install asyncpg with pip?: Yes
  • If you built asyncpg locally, which version of Cython did you use?: N/A
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : just uvloop

It seems like asyncpg's connection pooler is not gracefully terminating connections. This seems to happen only with AWS Aurora version, but not the locally installed Postgres version.

Aurora Postgre has idle_in_transaction_session_timeout set to 86400000.

Here is the code to help reproduce this issue. .

from sanic import Sanic, Blueprint
from sanic.exceptions import NotFound
from sanic.response import json
from sanic.handlers import ErrorHandler
import asyncpg

app = Sanic(name="asyncpg-errors")
bp = Blueprint("info", url_prefix="/info")


DB_CONFIG = {
    'host':<url>,
    'user': <user>,
    'password': <password>,
    'port': 5432,
    'database': 'postgres'
}

def log_listener(connection, message):
    print(message)

@app.listener('before_server_start')
async def init(app, loop):
    app.pool = await asyncpg.create_pool(
        **DB_CONFIG, loop=loop,
        max_size=10, max_inactive_connection_lifetime=1
    )

@bp.route('/', methods=['GET'])
async def info(request):
    async with request.app.pool.acquire() as conn:
        conn.add_log_listener(log_listener)
        d = await conn.fetchrow('''SELECT * FROM mmrtest limit 1''')
        return json(dict(d))




group = Blueprint.group(bp)
app.blueprint(group)

app.run(port=9091, access_log=True, debug=True)

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với bản tái hiện Sanic được cung cấp, tập trung vào asyncpg.create_pool, max_inactive_connection_lifetime và luồng acquire/release kết nối. Chạy bản này trên AWS Aurora và so sánh hành vi của nó với PostgreSQL cục bộ dưới uvloop. Công việc được xem là hoàn tất khi hành vi reset kết nối được giải thích và một bản sửa lỗi đã được xác minh hoặc bước tiếp theo có phạm vi giới hạn được ghi lại.

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ó
4/5
Thời gian dự kiến
3-5 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

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.