TLS stream corruption under concurrent threaded reads on macOS arm64
Maintainer thường phản hồi trong vòng 1 ngày
@bewithgaurav đang làm issue này rồi.
Từ ngày 20/7/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 478
- Fork
- 62
- Merge trung bình
- 3 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 27
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/mssql-python
-
area: bulk-copy
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
microsoft/mssql-python#843 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
macOS: encrypted connections fail after Homebrew moved the `openssl` alias to `openssl@4`Có thể đã có người làm @bewithgaurav đã nhận 14 ngày trước. Đang mởarea: packaging-platform bug triage needed
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
microsoft/mssql-python#826 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bulkcopy PyCore login is closed by SQL Server 2019 while ODBC and Go clients succeed (1.14.0)Có thể làm lại được @bewithgaurav đã nhận 34 ngày trước và không có pull request nào đang mở. Đang mởarea: bulk-copy bug triage done
microsoft/mssql-python#750 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Announcement: mssql-python is coming to Django through mssql-django 2.0Có thể làm lại được @bewithgaurav đã nhận 40 ngày trước và không có pull request nào đang mở. Đang mởannouncement
microsoft/mssql-python#748 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Connection pool can briefly exceed max_size when pooling is disabled under loadCó thể đã có người làm @bewithgaurav đã nhận 23 ngày trước. Đang mởarea: connectivity-auth bug triage done under development
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 62/100
microsoft/mssql-python#746 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của microsoft/mssql-python
Issue tương tự
-
[Bug]: LangGraph Store sync put bypasses namespace validationCó thể đã có người làm @ktz03 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
volcengine/OpenViking#6050 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Streamed /v1/chat/completions sends unredacted agent error text (keys) in the final chunkCó thể đã có người làm @rodricksz4h5 đã nhận hôm nay. Đang mởarea/streaming comp/gateway P2 type/security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NousResearch/hermes-agent#138245 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[oblt-aw][autodoc] Update user onboarding guide for mandatory trigger CODEOWNERS stepCó thể đã có người làm @github-actions đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
correction metadata
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 68/100
acl-org/acl-anthology#10378 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
cloudtrail_multi_region_enabled_logging_management_events fails when the advanced event selector has a custom nameCó thể đã có người làm @12YYCCYY16 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
prowler-cloud/prowler#13033 ·
Maintainer thường phản hồi trong vòng 1 ngày