TLS stream corruption under concurrent threaded reads on macOS arm64
Los mantenedores suelen responder en 2 días
@bewithgaurav ya está trabajando en esto.
Desde el 20/7/2026.
Evaluación
Este issue todavía no se ha evaluado.
Descripción
Summary
Concurrent threaded reads with Encrypt=yes can corrupt the TDS/TLS stream on macOS arm64. The issue reproduces with mssql-python 1.10.0 and also with pyodbc + Microsoft ODBC Driver 18, while the same workload is clean with Encrypt=no.
This does not appear to be a Python application pooling issue: the repro uses one private connection per thread, no SQLAlchemy pool, no shared connection/cursor objects, and synthetic constant data.
Environment
- OS: macOS arm64, Apple Silicon M5 Pro
- Python: 3.12
- mssql-python: 1.10.0
- pyodbc: 5.3.0, for comparison only
- Microsoft ODBC Driver: msodbcsql18 18.6.2.1, for comparison only
- unixODBC: 2.3.14, for comparison only
- OpenSSL: 3.6.3
- SQL Server: SQL Server 2025 RTM-CU6 in local Docker, x86_64 container under Rosetta
- Connection: local
localhost,1433,TrustServerCertificate=yes
Expected behavior
Two Python threads, each using its own independent database connection and cursor, should be able to fetch large result sets concurrently without corrupting returned row data or the protocol stream.
Actual behavior
With mssql-python and Encrypt=yes, repeated runs show intermittent failures and hangs. Examples include:
Driver Error: Communication link failure; DDBC Error: [Microsoft]The connection is no longer usable because the server response for a previously executed statement was incorrectly formatted.
In a small isolated process matrix using the same workload:
mssql-python Encrypt=yes: 4/10 clean, 4/10 corrupt, 2/10 timeout
mssql-python Encrypt=no: 10/10 clean, 0/10 corrupt, 0/10 timeout
The comparable pyodbc/msodbcsql18 repro shows the same pattern:
pyodbc + Encrypt=yes + threads: corrupt intermittently
pyodbc + Encrypt=no + threads: clean
pyodbc + Encrypt=yes + multiprocessing: clean
Typical pyodbc comparison errors include:
[Microsoft][ODBC Driver 18 for SQL Server]Protocol error in TDS stream (0) (SQLGetData)
[Microsoft][ODBC Driver 18 for SQL Server]Unknown token received from SQL Server (0) (SQLGetData)
SSL Provider: wrong version number / record layer failure
Minimal mssql-python repro
from __future__ import annotations
import os
import sys
import threading
from mssql_python import connect
PWD = os.environ["DB_PASSWORD"]
CONN = (
"Server=localhost,1433;"
"Database=orglith;"
f"UID=sa;PWD={PWD};"
"Encrypt=yes;"
"TrustServerCertificate=yes;"
)
Q = "SELECT TOP 200 REPLICATE(CAST('A' AS NVARCHAR(MAX)), 50000) FROM sys.all_objects a CROSS JOIN sys.all_objects b"
errors: list[tuple[str, str, str]] = []
def worker(who: str) -> None:
try:
with connect(CONN) as conn:
for i in range(5):
cur = conn.cursor()
cur.execute(Q)
rows = cur.fetchall()
for n, row in enumerate(rows):
value = row[0]
if len(value) != 50000 or value.count("A") != 50000:
raise ValueError(f"[{who} it={i} row={n}] corrupt: len={len(value)} count={value.count('A')}")
cur.close()
except Exception as exc:
errors.append((who, type(exc).__name__, str(exc)[:200]))
threads = [threading.Thread(target=worker, args=(f"t{i}",)) for i in range(2)]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
print("RESULT:", f"CORRUPT {errors}" if errors else "CLEAN")
sys.exit(1 if errors else 0)
Run several times, or from a parent script with subprocess timeouts, because failures are intermittent.
Control observations
- Changing only
Encrypt=yestoEncrypt=nomakes the workload clean in repeated runs. - Running the same logical workload in separate processes instead of threads is clean with TLS enabled.
- A pure Python/OpenSSL AES-GCM stress test and a Python
sslTLS echo stress test are clean on the same machine. - FreeTDS/pymssql and pytds TLS comparison reads are clean against the same SQL Server.
- Disabling pyodbc pooling does not explain the issue; the repro uses private connections and also reproduces in
mssql-python. MARS_Connection=Yes,PacketSize=8192, andOPENSSL_armcap=0were not reliable fixes under larger samples.
Why I am filing this here
The issue reproduces with mssql-python 1.10.0, so it is not isolated to pyodbc or unixODBC. Because mssql-python uses DDBC and the Microsoft native SQL Server/TDS stack, this looks like a lower-level TLS/TDS stream integrity issue on this macOS arm64 path.
I have not yet confirmed whether x86_64 Linux is affected; current confirmation is macOS arm64 only.
- Lenguaje dominante
- Python
- Estrellas
- 478
- Forks
- 62
- Merge medio
- 3 d 1 h
- PR fusionados (30 d)
- 26
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/mssql-python
-
area: bulk-copy triage needed
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
microsoft/mssql-python#843 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
bulkcopy() fails with SQL error 7339 for UTF-8 multibyte characters against Fabric WarehouseAbiertotriage needed
Dificultad 4/5 3-5 días Aptitud para principiantes 22/100
microsoft/mssql-python#849 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
triage needed
Dificultad 4/5 3-5 días Aptitud para principiantes 20/100
microsoft/mssql-python#848 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
triage needed
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
microsoft/mssql-python#846 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
macOS: encrypted connections fail after Homebrew moved the `openssl` alias to `openssl@4`Posiblemente ocupada @bewithgaurav la tomó hace 16 días. Abiertoarea: packaging-platform bug triage needed
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
microsoft/mssql-python#826 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 2 días
Todos los issues de microsoft/mssql-python
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
noontide-co/mainbranch#1211 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[1.x Bug] run-operation --sql reports success but rolls back writes on transaction-capable adaptersAbiertotriage
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
dbt-labs/dbt#16784 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
bug needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
bug settings ui
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
DewaldOosthuizen/py-tray-command-launcher#162 ·
Los mantenedores suelen responder en 1 día
-
run_all sleeps after the final job despite documenting delays between jobsPosiblemente ocupada @Gambit-Checkmate la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100