From 796609787edc0bb6d8ec046844417cf22fcbf321 Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Sat, 5 Dec 2026 20:33:16 +0300 Subject: [PATCH] System: fix Windows process pipe busy loop A synchronous zero-byte pipe read was stored as ready data, leaving communicate_blocking with nothing to wait on and no progress (a spin). Treat a zero-byte read as EOF in both the issue and completion paths. Make the stdout/stderr independence test use cmd.exe syntax on Windows. Wine 11, x86_64-w64-mingw32 GCC 16.2: full VoidTests.exe suite passes (1337 tests, 1323 passed, 14 skipped, 0 failed). Refs #65 --- src/System/ProcessWindows.cpp | 17 +++++++++++++++-- tests/standalone/System/Process.cpp | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/System/ProcessWindows.cpp b/src/System/ProcessWindows.cpp index 19f4393..f15f7dd 100644 --- a/src/System/ProcessWindows.cpp +++ b/src/System/ProcessWindows.cpp @@ -627,7 +627,16 @@ namespace &got, &stream.ov) != 0) { - stream.read_ready = got; + // A zero-byte success is EOF; storing it as "ready" data would + // leave the caller with nothing to wait on (busy loop). + if (got == 0) + { + stream.eof = true; + } + else + { + stream.read_ready = got; + } return; } const DWORD error = ::GetLastError(); @@ -688,8 +697,12 @@ namespace got = stream.read_ready; stream.read_ready = 0; } + if (got == 0) + { + return IoStatus::eof; + } bytes = got; - return got > 0 ? IoStatus::data : IoStatus::none; + return IoStatus::data; } void issue_write(WinStream& stream, diff --git a/tests/standalone/System/Process.cpp b/tests/standalone/System/Process.cpp index e115953..9142d2f 100644 --- a/tests/standalone/System/Process.cpp +++ b/tests/standalone/System/Process.cpp @@ -94,8 +94,12 @@ Void::Testing::Test run_missing_executable_returns_code_127() Void::Testing::Test run_stdout_and_stderr_independent() { +#ifdef _WIN32 + auto r = Void::Process::shell("echo to_stdout & echo to_stderr 1>&2"); +#else auto r = Void::Process::shell( "echo to_stdout; echo to_stderr >&2"); +#endif Void::Testing::expect(r.has_value()); Void::Testing::expect(r->out.find("to_stdout") != std::string::npos); Void::Testing::expect(r->err.find("to_stderr") != std::string::npos);