MagicStack / MagicStack/asyncpg

A weird log line from the asyncio default exception handler: "Resetting connection with an active transaction"

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

还没有人认领这个 Issue。

主要语言
Python
星标
8.1k
派生
469
平均合并
18 分钟
30 天内合并 PR
4

描述

Sometimes our production component logs the following error
21:05:49.897964000 [Error ] [asyncio] Resetting connection with an active transaction <asyncpg.connection.Connection object at 0x7fb1502561f8>

We create a connection pool first.
Then we use async_timeout, prepared statements, explicit transaction and a cursor to get data.
A coroutine that has this logic may be cancelled sometimes, and this is when we may see the error above. However not every
cancellation produces the error. Cancellation happens oftens but we see this error extremely rarely. I wasn't able to build a
minimal example to reproduce it.

We use a connection pool.
Later, in a different coroutine, we use async_timeout, prepared statements, explicit transaction and a cursor.
A coroutine that has this logic may be cancelled sometimes, and this is when we may see the error above. However not every
cancellation produces the error. Cancellation happens oftens but we see this error extremely rarely. I wasn't able to build a
minimal example to reproduce it.

`
pool = await asyncpg.create_pool(...)

        async with async_timeout.timeout(global_delay_sec) as cm:
            async with pool.acquire() as conn:
                stmt = await conn.prepare(sql)
                columns = stmt.get_attributes()
                ...
                async with conn.transaction():
                    cursor = await stmt.cursor()
                    raw_values = await cursor.fetch(max_rows + 1)
                    if len(raw_values) == max_rows + 1:
                        raise Exception(f"A total number of rows exceeded the allowed maximum of {max_rows} rows")

`

  • asyncpg version:
    0.20.1

  • PostgreSQL version:
    Reproduced with both postgres-11 and 12

  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    :
    No we don't use PostgreSQL SaaS
    I wasn't able to reproce it the issue locally.

  • Python version:
    3.6.3

  • Platform:
    lsb_release -d
    Description: CentOS Linux release 7.6.1810 (Core)

  • Do you use pgbouncer?:
    no

  • Did you install asyncpg with pip?:
    yes

  • If you built asyncpg locally, which version of Cython did you use?:
    We do not build it locally

  • Can the issue be reproduced under both asyncio and
    uvloop?
    :
    I do use uvloop, I couldn't reproduce it locally. It seems to be an extremely rare issue, happens in our production only once in a month

贡献指南

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

从这里开始

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

调研方向

从已报告的 pool.acquire、prepared-statement、显式事务、游标和 async_timeout 流程开始,重点关注所示操作期间的取消。使用列出的 PostgreSQL 版本比较 asyncio 和 uvloop 下的行为,并将仅在生产环境中出现的日志作为需要解释的症状。完成的标准是复现这个罕见的 reset,或确定一个已确认的原因和解决方案。

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

评估

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

把新 issue 发到你的邮箱

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