Skip to content

[Bug]: AsyncClient ignores connection and query timeout settings #30063

Closed

Description

@dengn

Existing issue check

  • 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: P1.

Actual behavior and reproduction

AsyncClient stores connection_timeout and query_timeout, but _create_async_engine() does not pass connection timeout and execute() has no query deadline. connect() defaults can also override constructor options. In SQLAlchemy 2.1, the SDK's plain SQLAlchemy dependency can omit the required greenlet async runtime and leave async imports unavailable.

Expected behavior and design

Respect inherited/explicit connection timeout. Bound the connection probe and the full AsyncClient.execute operation, including pool wait and result fetching, with a documented deadline. Cancellation must propagate and release pool capacity. A timed-out write must not be blindly retried or described as proven rollback.

Declare the async SQLAlchemy runtime dependency. This fix covers AsyncClient calls, not a new asynchronous Arrow API or every independently managed Session operation.

Acceptance tests

Assert driver options, constructor/explicit precedence, positive finite validation, cancellation/finally execution, stalled actual network result timeout, pool return/reuse and failed-connect disposal. Re-run against SQLAlchemy 1.4, 2.0 and 2.1 with proper package installation/runtime dependencies.

Implementation tracking

#30074 — draft implementation with regression cases and recorded local validation. Pending review/merge; the issue closes on merge.

Activity

  1. Ariznawlll commented on Oct 20, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:官方 main,完整 commit 21966565287edf9f7d7f519af60d269711608945;服务端 git_version()=2196656528。
    • 修复:PR fix(python-sdk): enforce handshake, TLS, redaction and async deadlines #30074,merge commit 8ef2eaf4d923bdb4136dd81a50850e8eced0f368;已通过 GitHub main compare 确认包含于执行时 main。
    • 部署方式:隔离 macOS arm64 mo-service(1 CN / 1 TN / 1 LogService,MySQL 127.0.0.1:6001)和独立 Python 3.12 SDK 虚拟环境;SQLAlchemy 2.1.5、aiomysql 0.3.2。仅使用本地测试库。
    • 测试日期:2026-10-20。

    原问题验证

    在真实 MO 协议连接上对 AsyncClient.execute 进行三轮端到端测试:query_timeout=0.05 执行 SELECT SLEEP(1),每轮均抛 asyncio.TimeoutError;检查 SQLAlchemy 连接池 checkedout()==0,然后恢复 3 秒期限执行 SELECT 1,每轮均返回 [(1,)]。另在执行 SELECT SLEEP(1) 期间显式取消 Python task,每轮均向调用方传播 asyncio.CancelledError、池占用回到 0,之后 SELECT 1 仍返回 [(1,)]。两条在线路径各 3/3 通过。

    Happy Path 覆盖

    1. 期限恢复后正常查询 SELECT 1,六次均返回精确值 1;取消或超时后没有耗尽连接池。
    2. 当前 main 的离线定向 test_connection_contracts.py + test_connection_redaction_transport.py 每轮 32 用例、3/3 轮通过;包含构造参数的 connect_timeout 传递到同步/异步驱动、显式超时值校验、成功连接探针和失败状态清理。加入连接 hooks 文件的定向运行 51/51 通过。

    Unhappy Path 覆盖

    1. 实际网络 SQL SELECT SLEEP(1) 超出短期限:3/3 抛超时、释放池连接且随后可用。
    2. 用户显式取消正在执行的真实网络 SQL:3/3 保留取消语义、释放池连接且随后可用。
    3. 离线定向覆盖 0、负数、布尔、NaN、Infinity 等无效期限被拒绝,以及失败连接探针后 engine dispose/状态清空;本轮没有把超时写入事务解释为已证明服务器回滚,写操作须另行核对后才可重试。

    白盒验证

    当前 main 的 AsyncClient.execute 对完整 _execute await 使用 asyncio.wait_for;_create_async_engine 将配置的 connect_timeout 传给驱动。离线定向三轮和真实网络超时/取消三轮与该实现一致。未运行 Python -race(不适用)。

    回归测试

    • PR fix(python-sdk): enforce handshake, TLS, redaction and async deadlines #30074 已合入 SDK 定向测试,覆盖超时配置、取消、连接清理及异步驱动参数;本轮在真实 MO 上重跑其 test_sdk_connection_contracts.py 的两个在线超时/取消用例各 3/3。此问题是 SDK API 的 deadline/pool 行为,不适合用纯 SQL MOTR 替代,故未追加 MOTR。
    • PR #30074 的 CI:六个 SDK offline cell 与 CI Required 为成功;SDK online job 被跳过。本轮独立运行了上述在线定向,但未运行整个 SDK online suite;其它 independently managed Session/Arrow API 不属于本 issue 声明的修复范围。

    测试证据

    • 隔离源码完整 SHA 与服务端 git_version() 如上;三轮在线命令每轮均显示两个测试通过,总计 timeout 3/3、explicit cancellation 3/3,各轮后的 checkedout()==0 和 SELECT 1 由断言核验。
    • 在线定向用例源码 和 PR #30074。
    • 本轮结论只针对 main SDK 的上述超时/取消契约,不声称 v4.2.5 发布包或独立 Session API 已验收。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions