is_connected and ping() report a dead connection as live (since 2.1.0)
维护者通常 5 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 76/100
调研方向
从 Connection.ping() 和 src/datajoint/connection.py 开始,检查 MySQL 和 PostgreSQL 适配器的 ping() 方法。检查 is_connected 如何处理 ping 失败,并查找可扩展的现有连接测试;issue 没有指定测试文件。完成标准是:连接断开时,ping() 会抛出异常,且 is_connected 返回 False,包括 PostgreSQL 的情况。
由索引模型根据 Issue 内容生成。
描述
Bug Report
Description
Connection.ping() no longer raises when the connection is dead, so Connection.is_connected stays True after the server kills the connection or stops. It only turns False after close(). We check is_connected in a health endpoint, and it reported a stopped server as connected.
Connection.ping() calls self.adapter.ping(self._conn) and discards the result. MySQLAdapter.ping() catches every exception and returns False, so ping() never raises, and is_connected never reaches its except branch.
Reproducibility
Include:
- OS: Linux (Ubuntu on WSL2)
- Python 3.12.13
- MySQL 8.4.11
- local-docker
- DataJoint 2.3.6 (the code is unchanged on master)
Steps:
import datajoint as dj
import pymysql
conn = dj.conn()
config = dj.config
admin = pymysql.connect(host=config['database.host'], port=config['database.port'],
user=config['database.user'], password=config['database.password'])
with admin.cursor() as cursor:
cursor.execute(f'KILL {conn.connection_id}')
print(conn.adapter.ping(conn._conn)) # False
print(conn.is_connected) # True
conn.ping() # does not raise
print(conn) # DataJoint connection (connected) root@...
Expected Behavior
ping() raises and is_connected returns False once the server has dropped the connection, as in 0.14.4 and 2.0.0, where ping() called self._conn.ping(reconnect=False) directly.
Additional Research and Context
- Introduced in 2.1.0, when ping() started going through the backend adapters.
- Connection.ping() ignores the adapter's result: https://github.com/datajoint/datajoint-python/blob/v2.3.6/src/datajoint/connection.py#L392-L401
- The adapters return False instead of raising: MySQL, PostgreSQL (the PostgreSQL case is not tested).
- repr (L251) and in_transaction (L531) read is_connected, so they are wrong in the same way.
- #1734 relies on is_connected noticing a dead connection ("Closed by close(), or found dead by is_connected").
- Possible fix: in Connection.ping(), raise errors.LostConnectionError when self.adapter.ping(self._conn) returns False.
- 主要语言
- Python
- 星标
- 198
- 派生
- 107
- 平均合并
- 4 天 7 小时
- 30 天内合并 PR
- 12
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
datajoint/datajoint-python 的其他 Issue
-
MySQL: with use_tls=False, 2.3.6 needs the cryptography package to log in to MySQL 8可能已有人在做 @dimitri-yatsenko 于 5 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 74/100
datajoint/datajoint-python#1750 ·
维护者通常 5 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
datajoint/datajoint-python#1747 ·
维护者通常 5 天内回复
-
Reject constant defaults on primary-key attributes可能已有人在做 @godara-alt 于 4 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 84/100
datajoint/datajoint-python#1712 ·
维护者通常 5 天内回复
-
Decoding a <blob> value in an unknown format returns None instead of raising an error可能已有人在做 @godara-alt 于 9 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 78/100
datajoint/datajoint-python#1703 ·
维护者通常 5 天内回复
-
staged_insert1 stores object paths with the class name and an empty store name, so garbage collection can delete its objects可能已有人在做 @godara-alt 于 9 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 78/100
datajoint/datajoint-python#1701 ·
维护者通常 5 天内回复
查看 datajoint/datajoint-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
pimutils/vdirsyncer#1242 ·
-
priority:P2
难度 2/5 1-3 小时 新手友好度 75/100
QuantConnect/lean-cli#792 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
open-webui/open-webui#35360 · 1 条评论 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
-
Suggest link: Destiny Verify (MIT zero-dependency pre-commit security, citation & link hygiene CLI)未关闭
难度 1/5 1 小时以内 新手友好度 68/100