Deadlock under concurrent multithreaded use when DEBUG logging is enabled via setup_logging()
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 10/7/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Describe the bug
When driver logging is enabled via mssql_python.setup_logging(output="file") (DEBUG level) and multiple threads concurrently open connections and execute statements (for example a ThreadPoolExecutor with 4 workers), the process permanently deadlocks. It sits at 0% CPU — fully frozen, not merely slow.
The same code with setup_logging not called does not deadlock. It also does not deadlock with a single worker thread. The trigger is therefore the combination of DEBUG logging + concurrency (workers > 1).
Environment
- mssql-python version: 1.10.0
- Python version: 3.12.11
- Operating system: macOS (arm64)
- Authentication:
ActiveDirectoryDefault(Entra ID) against a Microsoft Fabric Warehouse. The deadlock is in the logging path and is very likely authentication-independent.
Observed thread stacks
Captured with Python's faulthandler. The dumps were identical across 7 dumps over roughly 7 minutes, which confirms a permanent deadlock rather than slowness.
Thread A (opening a connection):
File ".../mssql_python/connection.py", line 571 in setautocommit
File ".../mssql_python/connection.py", line 410 in __init__
File ".../mssql_python/db_connection.py", line 55 in connect
-> (calls into Python logging) ...
File ".../logging/handlers.py", line 75 in emit
File ".../logging/__init__.py", line 1144 in flush # blocked here
Thread B (executing a statement, a COPY INTO):
File ".../mssql_python/cursor.py", line 1545 in execute # blocked in native execute
Server-side check
While the client is frozen, the database server shows no query running for this session. This confirms the block is entirely client-side and is not waiting on the server.
Hypothesized mechanism
mssql-python emits DEBUG log records from within native code paths (for example setautocommit during connect, and cursor.execute) that hold the GIL / internal locks. Under concurrency this creates a lock-acquisition cycle with Python's logging Handler locks across threads:
- Thread A holds the logging handler lock and is blocked in
flush. - Thread B is blocked in native
executeand cannot proceed.
This is a classic logging-from-native-under-the-GIL deadlock. It only reproduces with workers > 1.
Steps to reproduce (minimal sketch)
- Call
mssql_python.setup_logging(output="file")to enable DEBUG logging. - From
N >= 2threads, concurrently open connections (autocommit=True) and run statements against the same server.
The process deadlocks within seconds to a couple of minutes.
Expected behavior
Enabling DEBUG logging should not affect correctness. Concurrent, multithreaded workloads should run to completion whether or not setup_logging is enabled.
Workaround
Do not enable setup_logging for concurrent / multithreaded workloads.
Impact
This makes the DEBUG logging feature unusable for any multithreaded application (for example parallel data-loading), which is precisely the scenario where enabling DEBUG logging is most valuable for diagnosis.
Possibly related issues
The following existing issues appear related but are distinct from this report:
- #540 — GIL held for the entire duration of
cursor.execute()(describes the native-call-holds-GIL behaviour that is part of the hypothesized mechanism here, but is about starvation rather than a permanent deadlock and does not involve logging). - #321 — multithreaded hang/deadlock with 3+ threads (does not involve logging; closed as non-reproducible).
- #421 — hang with
setup_loggingenabled (single-threaded, diagnosed as a driver-load hang on Linux rather than a concurrency logging-lock deadlock).
- 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 41 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ự
-
vis.image() reports "Unsupported number of image channels: 224" for an HxWxC imageCó thể đã có người làm @piyush182004 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
fossasia/visdom#1997 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 6 ngày
-
Byse new domainĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Gujal00/ResolveURL#1525 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Serialisation fails with pydantic 2.14: wrap serialisers pass SerializationInfo as index_keyCó thể đã có người làm @hugohills-regnosys đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
finos/rune-python-runtime#45 ·
-
[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
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
hummingbot/condor#283 ·
Maintainer thường phản hồi trong vòng 1 ngày