Fix WinError 87 not handled in convert_oserror() (#2519) - #2970
Open
omprakash2929 wants to merge 1 commit into
Open
Fix WinError 87 not handled in convert_oserror() (#2519)#2970omprakash2929 wants to merge 1 commit into
omprakash2929 wants to merge 1 commit into
Conversation
Contributor
Author
|
@giampaolo This PR addresses the WinError 87 issue reported in #2519. Since the race condition is timing-dependent and hard to reproduce
Happy to adjust the approach if you'd prefer a different way to handle this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2519
Process.send_signal(CTRL_C_EVENT/CTRL_BREAK_EVENT)on Windows canraise a raw
OSError(WinError 87, "the parameter is incorrect")instead of
NoSuchProcess, when the target process terminates on itsown right before the signal is sent (race condition).
Root cause
convert_oserror()in_pswindows.pyonly convertsProcessLookupErrorand permission errors into psutil-friendly exceptions.
WinError 87raised by
os.kill()in this race condition wasn't handled, so itleaked out as a raw
OSError.Fix
Added a check for
winerror == 87inconvert_oserror(), convertingit into
NoSuchProcess, consistent with how other "processdisappeared" cases are already handled.
Testing
tests/test_windows.py::TestProcess::test_ctrl_signals= PASSEDtests/test_windows.py::TestProcess::test_send_signal= PASSEDstress test script; the underlying scenario is timing-dependent
(as noted by the original reporter), so the fix targets the error
code specifically, matching the documented
WinError 87behavior.