Intermittent no pg_hba.conf entry for host
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 asyncpg/pool.py 中的 _acquire、PoolConnectionHolder.acquire 和 _get_new_connection 开始,然后根据提供的 stack trace 跟踪 asyncpg/connect_utils.py,直到 __connect_addr。使用 PostgreSQL 15.10 和 asyncpg 0.30.0 重现反复出现的故障,并确定 pool acquisition 是否按预期处理报告的连接错误;如果适用,应通过 regression test 明确确定其行为及任何必要的变更,才算完成。
由索引模型根据 Issue 内容生成。
描述
I have a long-running script which initializes an asyncpg.Pool at the start of the script, then spawns a ton of tasks on an eventloop which occasionally acquire a connection, write something and put the connection back. An individual connection could in theory go a long time between usages, since the writes are only occasional. Plenty of time for some of them to idle out. That may be relevant here, because exactly every ten minutes, I get a few errors like this in my task log:
asyncpg.exceptions.InvalidAuthorizationSpecificationError: no pg_hba.conf entry for host
The script goes through its recovery logic, throwing away of bunch of work that the task already did, and the script resumes working again. The connections continue working again for another 10 minutes - plenty of writes get through, so this is not really an auth error - then the cycle repeats.
This feels like asyncpg acquires a connection which is invalidated in some way, then raises when it checks the connection but before passing it along. I am not sure why the connections are invalidated, but the extreme regularity of it implies that the connections failed a keepalive or idled out and asyncpg doesn't account for the possibility in the acquire logic. It's also very possible that I have initialized the pool incorrectly and I'm seeing expected behavior. My pool's connection settings are all default. The connection is directly to PG, no middleware.
PostgreSQL 15.10 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0, 64-bit
asyncpg 0.30.0
Here is what I believe is the relevant part of the stack trace. All stack frames above this are my own code and the exception is thrown on a async with pool.acquire() as conn: line.
Am I running into expected behavior?
File "/home/redacted/miniconda3/envs/redacted/lib/python3.12/site-packages/asyncpg/pool.py", line 864, in _acquire
return await _acquire_impl()
^^^^^^^^^^^^^^^^^^^^^
File "/home/redacted/miniconda3/envs/redacted/lib/python3.12/site-packages/asyncpg/pool.py", line 849, in _acquire_impl
proxy = await ch.acquire() # type: PoolConnectionProxy
^^^^^^^^^^^^^^^^^^
File "/home/redacted/miniconda3/envs/redacted/lib/python3.12/site-packages/asyncpg/pool.py", line 140, in acquire
await self.connect()
File "/home/redacted/miniconda3/envs/redacted/lib/python3.12/site-packages/asyncpg/pool.py", line 132, in connect
self._con = await self._pool._get_new_connection()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/redacted/miniconda3/envs/redacted/lib/python3.12/site-packages/asyncpg/pool.py", line 517, in _get_new_connection
con = await self._connect(
^^^^^^^^^^^^^^^^^^^^
File "/home/redacted/miniconda3/envs/redacted/lib/python3.12/site-packages/asyncpg/connection.py", line 2421, in connect
return await connect_utils._connect(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/redacted/miniconda3/envs/redacted/lib/python3.12/site-packages/asyncpg/connect_utils.py", line 1049, in _connect
conn = await _connect_addr(
^^^^^^^^^^^^^^^^^^^^
File "/home/redacted/miniconda3/envs/redacted/lib/python3.12/site-packages/asyncpg/connect_utils.py", line 891, in _connect_addr
return await __connect_addr(params_retry, False, *args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/redacted/miniconda3/envs/redacted/lib/python3.12/site-packages/asyncpg/connect_utils.py", line 934, in __connect_addr
await connected
- 主要语言
- Python
- 星标
- 8.1k
- 派生
- 469
- 平均合并
- 3 天 14 小时
- 30 天内合并 PR
- 17
环境准备
我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
MagicStack/asyncpg 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 72/100
MagicStack/asyncpg#1342 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 56/100
MagicStack/asyncpg#1340 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 28/100
MagicStack/asyncpg#1337 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 42/100
MagicStack/asyncpg#1330 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 38/100
MagicStack/asyncpg#1322 ·
维护者通常 1 天内回复
查看 MagicStack/asyncpg 的全部 Issue
相似的 Issue
-
namespace operations
难度 1/5 1 小时以内 新手友好度 82/100
EclipseFdn/open-vsx.org#13573 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
collective/icalendar#1854 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
rancher/rancher-ai-agent#412 ·
维护者通常 6 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
TUDelftGeodesy/DePSI#134 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
HenriquesLab/rxiv-maker#335 ·