1+ diff --git a/deps/uv/src/win/process.c b/deps/uv/src/win/process.c
2+ index 4e94dee90e13eede63d8e97ddc9992726f874ea9..f46f34289e8e7d3a2af914d89e6164b751a3e47d 100644
3+ --- a/deps/uv/src/win/process.c
4+ +++ b/deps/uv/src/win/process.c
5+ @@ -1308,16 +1308,34 @@ static int uv__kill(HANDLE process_handle, int signum) {
6+ /* Unconditionally terminate the process. On Windows, killed processes
7+ * normally return 1. */
8+ int err;
9+ + DWORD status;
10+
11+ if (TerminateProcess(process_handle, 1))
12+ return 0;
13+
14+ - /* If the process already exited before TerminateProcess was called,.
15+ + /* If the process already exited before TerminateProcess was called,
16+ * TerminateProcess will fail with ERROR_ACCESS_DENIED. */
17+ err = GetLastError();
18+ - if (err == ERROR_ACCESS_DENIED &&
19+ - WaitForSingleObject(process_handle, 0) == WAIT_OBJECT_0) {
20+ - return UV_ESRCH;
21+ + if (err == ERROR_ACCESS_DENIED) {
22+ + /* First check using GetExitCodeProcess() with status different from
23+ + * STILL_ACTIVE (259). This check can be set incorrectly by the process,
24+ + * though that is uncommon. */
25+ + if (GetExitCodeProcess(process_handle, &status) &&
26+ + status != STILL_ACTIVE) {
27+ + return UV_ESRCH;
28+ + }
29+ +
30+ + /* But the process could have exited with code == STILL_ACTIVE, use then
31+ + * WaitForSingleObject with timeout zero. This is prone to a race
32+ + * condition as it could return WAIT_TIMEOUT because the handle might
33+ + * not have been signaled yet.That would result in returning the wrong
34+ + * error code here (UV_EACCES instead of UV_ESRCH), but we cannot fix
35+ + * the kernel synchronization issue that TerminateProcess is
36+ + * inconsistent with WaitForSingleObject with just the APIs available to
37+ + * us in user space. */
38+ + if (WaitForSingleObject(process_handle, 0) == WAIT_OBJECT_0) {
39+ + return UV_ESRCH;
40+ + }
41+ }
42+
43+ return uv_translate_sys_error(err);
44+ @@ -1325,6 +1343,14 @@ static int uv__kill(HANDLE process_handle, int signum) {
45+
46+ case 0: {
47+ /* Health check: is the process still alive? */
48+ + DWORD status;
49+ +
50+ + if (!GetExitCodeProcess(process_handle, &status))
51+ + return uv_translate_sys_error(GetLastError());
52+ +
53+ + if (status != STILL_ACTIVE)
54+ + return UV_ESRCH;
55+ +
56+ switch (WaitForSingleObject(process_handle, 0)) {
57+ case WAIT_OBJECT_0:
58+ return UV_ESRCH;
0 commit comments