FEAT: Built-in configurable connection and transient-fault retry logic
Mantenedores costumam responder em até 1 dia
@Om-singhaI já está trabalhando nisso.
Desde 2/9/2026.
Avaliação
Esta issue ainda não foi avaliada.
Descrição
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.
- Linguagem predominante
- Python
- Estrelas
- 478
- Forks
- 62
- Merge médio
- 3d 1h
- PRs com merge (30d)
- 27
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de microsoft/mssql-python
-
area: bulk-copy
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
microsoft/mssql-python#843 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
macOS: encrypted connections fail after Homebrew moved the `openssl` alias to `openssl@4`Talvez já em andamento @bewithgaurav assumiu há 14 dias. Abertaarea: packaging-platform bug triage needed
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 55/100
microsoft/mssql-python#826 · 2 comentários · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
bulkcopy PyCore login is closed by SQL Server 2019 while ODBC and Go clients succeed (1.14.0)Talvez livre de novo @bewithgaurav assumiu há 34 dias e não há nenhum pull request aberto. Abertaarea: bulk-copy bug triage done
microsoft/mssql-python#750 · 4 comentários · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
Announcement: mssql-python is coming to Django through mssql-django 2.0Talvez livre de novo @bewithgaurav assumiu há 41 dias e não há nenhum pull request aberto. Abertaannouncement
microsoft/mssql-python#748 · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
Connection pool can briefly exceed max_size when pooling is disabled under loadTalvez já em andamento @bewithgaurav assumiu há 23 dias. Abertaarea: connectivity-auth bug triage done under development
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 62/100
microsoft/mssql-python#746 · 1 comentário · 1 responsável ·
Mantenedores costumam responder em até 1 dia
Todas as issues de microsoft/mssql-python
Issues semelhantes
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
Deltares/imod-python#1940 ·
Mantenedores costumam responder em até 1 dia
-
effort: low prio: low ready
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 82/100
digitalfabrik/integreat-cms#4621 ·
Mantenedores costumam responder em até 5 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
ioos/compliance-checker#1375 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Mantenedores costumam responder em até 1 dia