Repository navigation
windows.process_alive: check GetExitCodeProcess == STILL_ACTIVE - #10650
underiya-ai wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #10650 +/- ##
=======================================
Coverage 89.47% 89.48%
=======================================
Files 105 105
Lines 20343 20343
Branches 3199 3199
=======================================
+ Hits 18201 18203 +2
+ Misses 1489 1486 -3
- Partials 653 654 +1 ☔ View full report in Codecov by Harness. |
ThomasWaldmann
left a comment
There was a problem hiding this comment.
Thanks! The logic is correct:
GetExitCodeProcessworks with thePROCESS_QUERY_LIMITED_INFORMATIONaccess we already open the process with, so no extra access right is needed.- The handle is always closed via
finally, and returningTruewhenGetExitCodeProcessitself fails is the conservative choice.
Rebase needed: #10649 was squash-merged, so this branch still carries its three original commits and now conflicts with master. Please rebase onto master so that only the new changes remain (ideally squashed into one commit).
Some small things:
-
Please add a short comment that an exit code of 259 is indistinguishable from
STILL_ACTIVE, so a process that exited with 259 is treated as alive. That errs on the safe side and borg never exits with 259, so no logic change is needed, just the note. -
The new tests write the fake exit code via
exit_code_ptr._obj.value._objis an undocumented attribute of the objectbyref()returns. It works on CPython, but it is fragile. -
The scenario this PR is about can be tested with real processes instead of mocks:
- start a child process, check
process_alive(platform.node(), pid, 0)isTrue; - kill it,
wait()for it, and keep a handle to it open viawindows._OpenProcess(...); - check
process_alive(platform.node(), pid, 0)is nowFalse, then close the handle.
That would make the
_objmocks for this case unnecessary. TheERROR_ACCESS_DENIEDmock can stay, that case is hard to set up for real. - start a child process, check
-
Imports: please keep the stdlib imports together and sorted, separated by a blank line from
pytest:import ctypes import os import platform import tempfile import pytest
-
Two of the four test functions have a blank line after the docstring, the other two don't - please make them consistent.
482c81b to
49d0bbe
Compare
|
Thanks for the review! I've rebased onto |
What does this PR fix?
On Windows,
OpenProcess()still succeeds and returns a valid handle for a process that has already exited if another process (such as a parent launcher like Vorta) still holds an open handle to it. As a result,platform.windows.process_alive()could report an exited process as still alive.(Note: Built on top of #10649.)
Solution
GetExitCodeProcess()via_kernel32after opening the process handle withPROCESS_QUERY_LIMITED_INFORMATIONand verify that the exit code equalsSTILL_ACTIVE(259).try ... finally.src/borg/testsuite/platform/windows_test.pycovering bothSTILL_ACTIVEand exited-process open-handle cases.