FEAT: Built-in configurable connection and transient-fault retry logic
维护者通常 1 天内回复
@Om-singhaI 已经在做这个了。
开始于 2026年9月2日。
评估
这个 Issue 还没有评估数据。
描述
Summary
Add first-class, configurable retry logic to mssql-python so applications get transient-fault resiliency without hand-rolling their own retry loops. Today the only retry surface is the ODBC-level ConnectRetryCount/ConnectRetryInterval keywords, which only silently reconnect a dropped idle connection. They do not retry a connect() that fails transiently, nor a query that fails with a recoverable error (deadlock victim, lock/query timeout, or Azure SQL throttling such as 40197/40501/49918). Every app has to reimplement this, and most get the backoff, jitter, and "which errors are retriable" classification subtly wrong.
Motivation
- Parity with the .NET Microsoft.Data.SqlClient configurable retry providers (
SqlRetryLogicBaseProvider,SqlConnection.RetryLogicProvider/SqlCommand.RetryLogicProvider) and the Azure SDK retry-policy conventions. - Azure SQL Database and SQL Managed Instance routinely surface transient errors during failover, scaling, and throttling; robust handling is effectively required for production.
- Reduces copy-pasted, error-prone retry loops and centralizes the transient-error taxonomy in the driver where it can be maintained authoritatively.
Proposed API (for discussion)
A retry policy object, attachable at the connection level and overridable per cursor/execute:
from mssql_python import RetryPolicy, connect
policy = RetryPolicy(
max_attempts=3, # total tries, not extra retries
backoff="exponential", # "exponential" | "fixed" | "none"
base_delay=1.0, # seconds
max_delay=30.0, # cap per wait
jitter=True, # full jitter to avoid thundering herd
# Retriable classification, defaulted by the driver but overridable:
# connect-scope errors -> fresh connection; query-scope -> same connection
)
conn = connect(conn_str, retry_policy=policy) # applies to connect() + queries
cursor = conn.cursor(retry_policy=policy) # optional override
cursor.execute(sql, *params, retry_policy=policy) # optional per-call override
Key behaviors:
- Two scopes, because recovery differs: connection-establishment/connection-loss errors need a fresh connection; connection-surviving errors (deadlock, query timeout, throttling) retry on the same connection.
- Driver-maintained default retriable set (transient SQLSTATEs / native error numbers), overridable by the caller.
- Idempotency guardrail: by default only retry statements the caller marks safe, or document clearly that writes must be wrapped in an explicit transaction. Never silently replay a non-idempotent write.
- Observability: emit standard
loggingrecords on each retry (attempt count, error, delay) and on final give-up. - No behavior change by default (opt-in), so existing code is unaffected.
Alternatives considered
- ODBC
ConnectRetryCount/ConnectRetryInterval— only covers idle-connection reconnect, notconnect()or query retries. - Application-level helper loops — what everyone does now; duplicative and easy to get wrong (backoff, jitter, error classification, connect-vs-query scope).
Additional context
Docs currently ship a sample connect_with_retry / execute_with_retry pattern that demonstrates exactly this behavior and would map cleanly onto a built-in RetryPolicy.
- 主要语言
- Python
- 星标
- 478
- 派生
- 62
- 平均合并
- 3 天 1 小时
- 30 天内合并 PR
- 27
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/mssql-python 的其他 Issue
-
area: bulk-copy
难度 2/5 1-3 小时 新手友好度 70/100
microsoft/mssql-python#843 · 1 条评论 ·
维护者通常 1 天内回复
-
macOS: encrypted connections fail after Homebrew moved the `openssl` alias to `openssl@4`可能已有人在做 @bewithgaurav 于 14 天前认领。 未关闭area: packaging-platform bug triage needed
难度 4/5 3-5 天 新手友好度 55/100
microsoft/mssql-python#826 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
bulkcopy PyCore login is closed by SQL Server 2019 while ODBC and Go clients succeed (1.14.0)可能重新可做 @bewithgaurav 于 34 天前认领,目前没有进行中的 PR。 未关闭area: bulk-copy bug triage done
microsoft/mssql-python#750 · 4 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Announcement: mssql-python is coming to Django through mssql-django 2.0可能重新可做 @bewithgaurav 于 41 天前认领,目前没有进行中的 PR。 未关闭announcement
microsoft/mssql-python#748 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Connection pool can briefly exceed max_size when pooling is disabled under load可能已有人在做 @bewithgaurav 于 23 天前认领。 未关闭area: connectivity-auth bug triage done under development
难度 4/5 3-5 天 新手友好度 62/100
microsoft/mssql-python#746 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 microsoft/mssql-python 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 72/100
-
[Bug]: Importing weave changes the process-wide locale可能已有人在做 @himanshu748 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
-
bug
难度 2/5 1-3 小时 新手友好度 74/100
-
UX
难度 1/5 1 小时以内 新手友好度 72/100
mediajunkie/piper-morgan-product#2008 · 2 条评论 ·