Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e7248ce

Browse files
committed
fix(pidExists): handle Windows-specific error codes for process existence check
1 parent 8db8503 commit e7248ce

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/Pids.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { isWin } from "./Platform";
2+
13
/**
24
* @param {number} pid process id. Required.
35
* @returns boolean true if the given process id is in the local process
@@ -15,6 +17,13 @@ export function pidExists(pid: number | undefined): boolean {
1517
// exist. EPERM means it _does_ exist!
1618
if ((err as NodeJS.ErrnoException)?.code === "EPERM") return true;
1719

20+
// On Windows, some error codes might indicate the process is terminating
21+
// but hasn't fully exited yet. Treat these as "not existing" to avoid
22+
// race conditions during shutdown.
23+
if (isWin && (err as NodeJS.ErrnoException)?.code === "EINVAL") {
24+
return false;
25+
}
26+
1827
// failed to get priority--assume the pid is gone.
1928
return false;
2029
}

0 commit comments

Comments
 (0)