From 6fee57e8416d209343956434c79c872d941c7715 Mon Sep 17 00:00:00 2001 From: Alex Hochheiden Date: Mon, 2 Mar 2026 15:50:52 -0800 Subject: [PATCH] bug 2020056: Fix Glean log pipe corruption on Windows --- glean-core/python/glean/_ffi.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/glean-core/python/glean/_ffi.py b/glean-core/python/glean/_ffi.py index 8d4a972f71..4710007a1c 100644 --- a/glean-core/python/glean/_ffi.py +++ b/glean-core/python/glean/_ffi.py @@ -5,6 +5,7 @@ import json import logging import os +import sys import threading @@ -26,7 +27,16 @@ def setup_logging(): Must be called after the Glean core has been dlopen'd. """ r, w = os.pipe() - glean_enable_logging_to_fd(w) + + if sys.platform == "win32": + # On Windows, os.pipe() returns C runtime file descriptors, but the + # Rust FdLogger expects a native Windows HANDLE (via FromRawHandle). + # Convert to a proper HANDLE with msvcrt.get_osfhandle(). + import msvcrt + + glean_enable_logging_to_fd(msvcrt.get_osfhandle(w)) + else: + glean_enable_logging_to_fd(w) reader = os.fdopen(r, encoding="utf-8")