You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Python Client reports connected after an unsuccessful connection probe #30060
Checked relevant Python SDK issues; this report concerns the SDK client path.
Environment
Repository main 3e50e1b32d8da61bbbf70c89989fb08b671809de, Python 3.12, SQLAlchemy 1.4/2.x. Initial findings were reproduced offline with synthetic inputs; real-service validation will be linked from the implementation PR.
Priority: P0.
Actual behavior and reproduction
Mock the lazy engine factory and make version-query execution raise an unreachable-endpoint error. Call connect(database='test', on_connect=[]). The probe error is swallowed and connected() returns True because it only checks engine existence; success is logged before an authenticated query succeeds.
Expected behavior
A successful connect must include an authenticated query. Unreachable host, rejected authentication and failed initialization must leave no usable engine/pool and must not log success. Dispose old engines on reconnect and reclaim failed new engines. connected() describes successful initialization; live health checks remain distinct.
Design and acceptance tests
Perform a required SELECT 1 before manager/version initialization and success reporting. Dispose and clear a failed engine while preserving the primary error and cancellation. Tests must verify successful handshake, failure/disposal, no success log on failure, reconnect cleanup, real unreachable port, invalid credentials and pool reuse.
Implementation tracking
#30074 — draft implementation with regression cases and recorded local validation. Pending review/merge; the issue closes on merge.
Validation follow-up for merged PR #30074: I found one remaining sync-client observability gap in clients/python/matrixone/client.py. Client.connect() logs success=True immediately after the SELECT 1 probe, before _initialize_vector_managers() and _execute_connection_hook_immediately(). If either post-probe initialization step raises, the exception path clears/disposes the engine and logs failure, but the success event has already been emitted. That contradicts this issue's acceptance condition that failed initialization must not log success.
A focused regression can let the probe succeed, make _initialize_vector_managers() raise, and assert connect() raises, the engine is disposed/cleared, and no log_connection(success=True) call occurs. The merged tests cover probe failure, but I did not find this post-probe initialization failure case in test_connection_contracts.py. I left this issue open for that gap.
Local validation update (2026-10-20)
Reproduced against MatrixOne HEAD 21966565287edf9f7d7f519af60d269711608945 using the actual Python SDK implementation: the mocked SELECT 1 probe succeeds, then _initialize_managers raises an injected initialization error. connect() raises ConnectionError and connected() is false after cleanup, but the captured connection-success flags are [True, False]. This confirms the false success event is emitted before initialization completes.
Also reran pytest -q clients/python/tests/offline at that HEAD: passed (warnings only).
Activity
XuPeng-SH commentedon Oct 20, 2026
Validation follow-up for merged PR #30074: I found one remaining sync-client observability gap in
clients/python/matrixone/client.py.Client.connect()logssuccess=Trueimmediately after theSELECT 1probe, before_initialize_vector_managers()and_execute_connection_hook_immediately(). If either post-probe initialization step raises, the exception path clears/disposes the engine and logs failure, but the success event has already been emitted. That contradicts this issue's acceptance condition that failed initialization must not log success.A focused regression can let the probe succeed, make
_initialize_vector_managers()raise, and assertconnect()raises, the engine is disposed/cleared, and nolog_connection(success=True)call occurs. The merged tests cover probe failure, but I did not find this post-probe initialization failure case intest_connection_contracts.py. I left this issue open for that gap.Local validation update (2026-10-20)
Reproduced against MatrixOne HEAD
21966565287edf9f7d7f519af60d269711608945using the actual Python SDK implementation: the mockedSELECT 1probe succeeds, then_initialize_managersraises an injected initialization error.connect()raisesConnectionErrorandconnected()is false after cleanup, but the captured connection-success flags are[True, False]. This confirms the false success event is emitted before initialization completes.Also reran
pytest -q clients/python/tests/offlineat that HEAD: passed (warnings only).Ariznawlll commentedon Oct 23, 2026
测试版本
main(官方matrixorigin/matrixone)91639500503a301742e0c84c8aa6c524f1e70792;fix(python-sdk): enforce handshake, TLS, redaction and async deadlines #30074 的合并提交8ef2eaf4d923bdb4136dd81a50850e8eced0f368和补漏 PR fix(python-sdk): redact create_table diagnostics and gate the success log #30678 的合并提交e47f45ca6548e198e73ecb242521047bfd449850均已核实为该 SHA 的祖先。vcs.modified=false的本机独立 1 Log / 1 TN / 1 CN 服务;每轮使用唯一命名的临时测试库,另跑 SDK 离线契约测试。原问题验证
使用真实 SQLAlchemy/PyMySQL 连接到本机 MatrixOne,而非仅构造 mock engine。
Client.connect(..., on_connect=[])成功时实际完成认证及SELECT 1,connected()为 true、连接成功日志标记为[True];错误密码、不可达端口以及认证探测成功后注入 manager 初始化异常时,connect()均抛出连接异常,connected()为 false、_engine已清空,成功日志均未出现,标记实际为[False]。实库探测连续 3/3 轮通过;特别覆盖了此前评论指出的“探测通过但后续初始化失败仍先记录成功”的残留点。Happy Path 覆盖
dispose()实际调用 1 次,新的连接仍可用。3/3 轮一致。Unhappy Path 覆盖
dispose()恰好调用 1 次,3/3。dispose()恰好调用 1 次,3/3。SELECT 1成功后注入 manager 初始化失败:连接抛错并释放/清空 Engine,dispose()恰好调用 1 次,仅记录失败,不会先记录成功,3/3。finally中删除;未写入共享环境。白盒验证
clients/python/tests/offline/test_connection_contracts.py独立执行 3 次,每次 23 个测试均通过,覆盖探测失败清理、认证后成功门槛、初始化失败日志、异步与超时等已有 SDK 契约。回归测试
connected()、Engine 池释放及logger.log_connection(success=...)时序。仅靠 MOTR 公共 SQL/协议无法观察这些内部状态,添加 SQL-only 用例不能捕获原缺陷;fix(python-sdk): enforce handshake, TLS, redaction and async deadlines #30074/fix(python-sdk): redact create_table diagnostics and gate the success log #30678 已在 SDK 自身的test_connection_contracts.py内提供针对性回归。本次没有新加不具备断言能力的 MOTR 用例,也未向 MatrixOne 仓库提交新 PR。CI Required已通过;其 online CI 为 skipped。远端 online CI 不作为本次通过依据,本次实库验收为上述本机 3/3 次。测试证据
initial_connect=PASS、reconnect_disposes_old_pool=PASS、invalid_auth_no_false_success=PASS、unreachable_no_false_success=PASS、post_probe_init_no_false_success=PASS、failed_pool_disposal=PASS;对应 SDK 契约测试每轮均为 23/23 通过。测试结论
测试通过。