Fix preinstall deadlock on Windows by using COREPACK_PACKAGE_MANAGER_LOCATOR (#799)#801
Open
AMDphreak wants to merge 2 commits intonodejs:mainfrom
Open
Fix preinstall deadlock on Windows by using COREPACK_PACKAGE_MANAGER_LOCATOR (#799)#801AMDphreak wants to merge 2 commits intonodejs:mainfrom
AMDphreak wants to merge 2 commits intonodejs:mainfrom
Conversation
…LOCATOR - Introduce COREPACK_PACKAGE_MANAGER_LOCATOR to ensure sub-invocations use the current binary version. - Bypass shim/PATH resolution in executePackageManagerRequest if the locator is already set. - This prevents race conditions where child processes (like preinstall scripts) try to access a shim that is being updated or locked by the main process.
MikeMcC399
suggested changes
Mar 4, 2026
Contributor
MikeMcC399
left a comment
There was a problem hiding this comment.
As far as I can judge, this PR fails linting and tests. Both would need to be fixed.
It also introduces a new environment variable COREPACK_PACKAGE_MANAGER_LOCATOR which is undocumented in the README.
Again, note that I am not a maintainer.
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.
This PR fixes a deadlock/race condition on Windows where project preinstall scripts that invoke the package manager (e.g., pnpm dlx only-allow pnpm) can crash during corepack use because the global shim is being re-linked or locked by Corepack. This is documented in #799.\n\n### Fix\nIn
unVersion, we now set the COREPACK_PACKAGE_MANAGER_LOCATOR environment variable. In �xecutePackageManagerRequest, we check this variable. If it matches the requested binary, we use it directly to bypass the project specification lookup and shim resolution.\n\n### Why this helps\nThis ensures that child processes sparked by the package manager during lifestyle scripts use the already-resolved version immediately, avoiding any interaction with external shims that might be in a transient or locked state.