fix(windows): use unique named pipe paths derived from PM2_HOME#6104
Open
KYUUUW wants to merge 1 commit intoUnitech:masterfrom
Open
fix(windows): use unique named pipe paths derived from PM2_HOME#6104KYUUUW wants to merge 1 commit intoUnitech:masterfrom
KYUUUW wants to merge 1 commit intoUnitech:masterfrom
Conversation
Windows named pipes live in a flat global namespace (\.\pipe\*). The current hardcoded names (rpc.sock, pub.sock, interactor.sock) cause EPERM errors when: - Multiple users run PM2 on the same machine - A zombie pipe from a crashed daemon blocks the name - PM2 is started from different elevation levels (admin vs user) This has been a known issue since 2017 (see Unitech#2946, Unitech#5212, Unitech#5510) and the code already contained a @todo comment acknowledging it. The fix derives a short hash from PM2_HOME and embeds it in the pipe name (e.g. \.\pipe\pm2-a1b2c3d4-rpc.sock), ensuring each PM2_HOME gets its own isolated set of IPC pipes. Note: The same fix is needed in @pm2/agent/constants.js which duplicates the Windows pipe name logic. Fixes Unitech#5510 Fixes Unitech#2946 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Problem
On Windows, PM2 hardcodes named pipe paths to
\.\pipe\rpc.sock,\.\pipe\pub.sock, and\.\pipe\interactor.sock(inpaths.jsline 84-87). Since Windows named pipes live in a flat global kernel namespace, this causesconnect EPERM //./pipe/rpc.sockerrors when:The code already had a
@todocomment acknowledging this://@todo instead of static unique rpc/pub file custom with PM2_HOME or UIDThis issue has been reported since 2017 (#2946) and remains unfixed in PM2 6.0.14.
Solution
Derive a short hash from
PM2_HOMEand embed it in the pipe name:This ensures each
PM2_HOMEgets its own isolated set of IPC pipes, eliminating collisions.What this fixes
PM2_HOMEpathEPERMfrom zombie pipes blocking the global namePM2_HOMEdirectories work correctly on WindowsPM2_HOME-relative paths)Note
The same hardcoded pipe names also exist in
@pm2/agent(constants.jsline 93-96). That package needs a matching fix — happy to submit a PR there as well if you point me to the right repo.Tested on
Fixes #5510
Fixes #2946
Related: #5212, #3859, #4851