From 3ad4bef38b5b459f9cd85b18aa8a569bdc8be452 Mon Sep 17 00:00:00 2001 From: Uttam Bhadauriya Date: Thu, 15 Oct 2026 18:46:25 +0530 Subject: [PATCH] gh-159118: Use MTA COM initialization in _wmi to avoid crashes under load Initialize COM with COINIT_MULTITHREADED instead of COINIT_APARTMENTTHREADED in _wmimodule.cpp to prevent hidden window registration contention and RPC_NT_INTERNAL_ERROR crashes under high concurrency. --- .../next/Windows/2026-10-15-18-45-00.gh-issue-159118.wmiMTA.rst | 1 + PC/_wmimodule.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Windows/2026-10-15-18-45-00.gh-issue-159118.wmiMTA.rst diff --git a/Misc/NEWS.d/next/Windows/2026-10-15-18-45-00.gh-issue-159118.wmiMTA.rst b/Misc/NEWS.d/next/Windows/2026-10-15-18-45-00.gh-issue-159118.wmiMTA.rst new file mode 100644 index 000000000000000..561a5005b759755 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2026-10-15-18-45-00.gh-issue-159118.wmiMTA.rst @@ -0,0 +1 @@ +Fix a crash (``RPC_NT_INTERNAL_ERROR``) and intermittent window class failures in :mod:`!_wmi` under high concurrency and load by initializing COM as multi-threaded (MTA) instead of apartment-threaded (STA). diff --git a/PC/_wmimodule.cpp b/PC/_wmimodule.cpp index b9a229b1398ec8d..a546313529fd1b1 100644 --- a/PC/_wmimodule.cpp +++ b/PC/_wmimodule.cpp @@ -67,7 +67,7 @@ _query_thread(LPVOID param) } if (SUCCEEDED(hr)) { - hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); + hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED); } if (FAILED(hr)) {