MagicStack / MagicStack/asyncpg
ConnectionDoesNotExistError when releasing
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 8.1k
- 派生
- 468
- PR 合并指标
- 30 天内没有已合并 PR
描述
* **asyncpg version**: 0.21.0
* **PostgreSQL version**: 10.7
* **Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?**: no
* **Python version**: 3.7
* **Platform**: debian (docker image `python:3.7.9-slim`)
* **Do you use pgbouncer?**: no
* **Did you install asyncpg with pip?**: yes
* **If you built asyncpg locally, which version of Cython did you use?**: no
* **Can the issue be reproduced under both asyncio and
[uvloop](https://github.com/magicstack/uvloop)?**: only tried asyncio
I've found the following exception in our logs:
```
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/asyncpg/pool.py", line 214, in release
self._con.terminate()
AttributeError: 'NoneType' object has no attribute 'terminate'
During handling of the above exception, another exception occurred:
File "/usr/local/lib/python3.7/site-packages/my_code_calling_release.py", line 40, in acquire
await self.pool.release(con)
File "/usr/local/lib/python3.7/site-packages/asyncpg/pool.py", line 654, in release
return await asyncio.shield(ch.release(timeout))
File "/usr/local/lib/python3.7/site-packages/asyncpg/pool.py", line 216, in release
raise ex
File "/usr/local/lib/python3.7/site-packages/asyncpg/pool.py", line 206, in release
await self._con.reset(timeout=budget)
File "/usr/local/lib/python3.7/site-packages/asyncpg/connection.py", line 1137, in reset
await self.execute(reset_query, timeout=timeout)
File "/usr/local/lib/python3.7/site-packages/asyncpg/connection.py", line 295, in execute
return await self._protocol.query(query, timeout)
File "asyncpg/protocol/protocol.pyx", line 316, in query
```
From what I can see, the call at `self._con.reset` is raising a `ConnectionDoesNotExistError`.
Should the exception be reraised at line 218 if the exception is an `ConnectionDoesNotExistError` (we know it's already closed)? It shouldn't even try to `self._con.terminate()` because `self._con` is already None (see the exception).
Not sure if the comments in that code still apply for that type of exception
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
阅读 asyncpg/pool.py 第 206-218 行附近的 release 路径以及 asyncpg/connection.py 中的 reset 路径,重点关注 ConnectionDoesNotExistError 如何使 self._con 保持为 None。复现或添加一个释放已关闭连接的回归用例,然后验证 release 不会尝试终止缺失的连接,并保留预期的异常行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- postgresql, python
- 领域
- databases
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100