[Bug] Windows PID liveness probe can send Ctrl+C to the shared console
Description
_is_pid_alive() currently calls os.kill(pid, 0) before applying Windows-specific error handling. On Windows, signal value 0 maps to CTRL_C_EVENT, so this can generate a console control event instead of performing a side-effect-free process existence check.
When the lock owner shares a console or process group with the probing process, checking .openviking.pid can interrupt OpenViking or its parent terminal with Ctrl+C/KeyboardInterrupt.
This is separate from the stale-PID behavior fixed by #790: that change handles WinError 87, but the liveness probe still calls os.kill(pid, 0) first.
Reproduction
- Run OpenViking on Windows from a console.
- Have a live process in the same console/process group recorded in
.openviking.pid. - Start another OpenViking process against the same data directory so that
_is_pid_alive()probes that PID. - The probe can generate a console
Ctrl+Cevent instead of only querying process state.
A regression test can make this deterministic by replacing os.kill with a function that fails the test, then calling _is_pid_alive(os.getpid()) on Windows. A liveness query must never reach os.kill on that platform.
Expected behavior
Windows PID liveness checks should not send any signal or console control event. They should:
- return
Falseonly when the PID is confirmed missing; - preserve the lock when access is denied and the process may still be alive;
- close any native process handle on every path.
Suggested direction
Use the native process handle APIs exposed by _winapi: open the process with SYNCHRONIZE, query it with WaitForSingleObject(handle, 0), and always call CloseHandle.
Related platform-specific PID work: #1088 and #4210.
Taking this — will switch _is_pid_alive on Windows to _winapi.OpenProcess(SYNCHRONIZE) + WaitForSingleObject so the liveness probe never calls os.kill(pid, 0) / Ctrl+C.