FEAT: Built-in configurable connection and transient-fault retry logic
Les mainteneurs répondent en général sous 1 jour
@Om-singhaI y travaille déjà.
Depuis le 2/9/2026.
Évaluation
Cette issue n'a pas encore été évaluée.
Description
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.
- Langage dominant
- Python
- Étoiles
- 478
- Forks
- 62
- Merge moyen
- 3 j 1 h
- PR mergées (30 j)
- 27
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de microsoft/mssql-python
-
area: bulk-copy
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
microsoft/mssql-python#843 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
macOS: encrypted connections fail after Homebrew moved the `openssl` alias to `openssl@4`Peut-être pris @bewithgaurav l’a pris il y a 14 jours. Ouvertearea: packaging-platform bug triage needed
Difficulté 4/5 3-5 jours Accessibilité débutants 55/100
microsoft/mssql-python#826 · 2 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
bulkcopy PyCore login is closed by SQL Server 2019 while ODBC and Go clients succeed (1.14.0)Peut-être à nouveau libre @bewithgaurav l’a pris il y a 34 jours, et aucune pull request n’est ouverte. Ouvertearea: bulk-copy bug triage done
microsoft/mssql-python#750 · 4 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Announcement: mssql-python is coming to Django through mssql-django 2.0Peut-être à nouveau libre @bewithgaurav l’a pris il y a 41 jours, et aucune pull request n’est ouverte. Ouverteannouncement
microsoft/mssql-python#748 · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Connection pool can briefly exceed max_size when pooling is disabled under loadPeut-être pris @bewithgaurav l’a pris il y a 23 jours. Ouvertearea: connectivity-auth bug triage done under development
Difficulté 4/5 3-5 jours Accessibilité débutants 62/100
microsoft/mssql-python#746 · 1 commentaire · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de microsoft/mssql-python
Issues similaires
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 72/100
-
[Bug]: Importing weave changes the process-wide localePeut-être pris @himanshu748 l’a pris aujourd’hui. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
-
UX
Difficulté 1/5 Moins d'une heure Accessibilité débutants 72/100
mediajunkie/piper-morgan-product#2008 · 2 commentaires ·