MagicStack / MagicStack/asyncpg

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

未关闭
#736 2 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
8.1k
派生
468
PR 合并指标
30 天内没有已合并 PR

描述

  • 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)

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从提供的 Sanic 复现开始,重点关注 asyncpg.create_pool、max_inactive_connection_lifetime 以及连接获取/释放路径。在 AWS Aurora 上运行它,并将其行为与 uvloop 下的本地 PostgreSQL 进行比较。当连接重置行为得到解释,并且记录了经过验证的修复方案或范围明确的下一步时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
postgresql, python
领域
backend, databases
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。