OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Bug] Windows PID liveness probe can send Ctrl+C to the shared console

Open nextCY opened this issue 2 months ago • 1 comments

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

  1. Run OpenViking on Windows from a console.
  2. Have a live process in the same console/process group recorded in .openviking.pid.
  3. Start another OpenViking process against the same data directory so that _is_pid_alive() probes that PID.
  4. The probe can generate a console Ctrl+C event 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 False only 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.

nextCY avatar Sep 07 '26 07:09 nextCY

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.

ktz03 avatar Sep 08 '26 14:09 ktz03