Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

win: almost fix race detecting ESRCH in uv_kill #4341

Merged
merged 1 commit into from
Mar 5, 2024

Conversation

santigimeno
Copy link
Member

It might happen that only using WaitForSingleObject() with timeout 0 could return WAIT_TIMEOUT as the process might not have been signaled yet. To improve things, first use GetExitCodeProcess() and check that status is not STILL_ACTIVE. Then, to cover for the case that the exit code was actually STILL_ACTIVE use WaitForSingleObject(). This could still be prone to the race condition but only for that case.

Fixes: nodejs/node#51766

Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good find. I assumed that TerminateProcess was a synchronization barrier since it used terms like "after", but apparently the kernel doesn't those implement semantics correctly.

Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you copy this same code into the "health check" case? I would find it confusing if kill(SIGINT) returned ESRCH, and then kill(0) returned 0

src/win/process.c Outdated Show resolved Hide resolved
src/win/process.c Outdated Show resolved Hide resolved
@santigimeno
Copy link
Member Author

I think this is done @vtjnash ptal, thanks

It might happen that only using `WaitForSingleObject()` with timeout 0
could return WAIT_TIMEOUT as the process might not have been signaled
yet. To improve things, first use `GetExitCodeProcess()` and check
that `status` is not `STILL_ACTIVE`. Then, to cover for the case that the exit
code was actually `STILL_ACTIVE` use `WaitForSingleObject()`. This could
still be prone to the race condition but only for that case.
@santigimeno santigimeno merged commit ff95879 into libuv:v1.x Mar 5, 2024
14 of 15 checks passed
@santigimeno santigimeno deleted the santi/win_kill_esrch branch March 5, 2024 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

childprocess kill() results in -4048 EPERM error on windows since update to v21.6.2
2 participants