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

[BUG] Running shims from shims directory results in freezing with no output #129

Open
iki opened this issue Oct 16, 2024 · 4 comments
Open
Labels
bug Something isn't working

Comments

@iki
Copy link

iki commented Oct 16, 2024

Describe the bug

Running node/npm/npx/corepack shims from shims directory results in freezing with no output and can only be interrupted with Ctrl+C.

When running from any other directory they work as expected.

To Reproduce

Steps to reproduce the behavior:

  1. Install NVM.Desktop_4.0.1_x64-setup.exe on Windows 11 x64
  2. Install Node v22.9.0 via NVM Desktop
  3. [OK] Optionally check %UserProfile%\.nvmd\bin is in PATH
  4. [OK] Optionally check Node v22.9.0 is installed in %UserProfile%\.nvmd\versions\22.9.0
  5. Set default Node version (see [BUG] nvm-desktop: command not found: "node" after installing first Node version from GUI without running nvmd use {version} #128)
$ nvmd use v22.9.0
Now using node v22.9.0
  1. [OK] Try running node/npm/npx/corepack via nvmd shim. Here I use explicit path to be sure:
$ "%UserProfile%\.nvmd\bin\node.exe" --version
  1. [BUG] Try running node/npm/npx/corepack via nvmd shim from shim directory:
$ cd "%UserProfile%\.nvmd\bin"
$ node.exe --version
# No output, frozen, can be interrupted with Ctrl+C, results in lines below
^C^C^C^C^C^C^C^C^C^C^C^^C^C^C^C^C^C^C^^C^C^C^C^^^C^^C^C^C^C^C^C^^C^C^^^C^C^C^C^^C^C^C^C^C^C^C^C^C^C^C^C^^C^^^^C^C^C^C^^C
^^^C^C^C^C^C^C^C^CCC^C^C^C^CC^CCC^C^^C^C^C^C^C^C^CC^CCC^C^C←]4;0;rgb:00/00/00←\←]4;4;rgb:00/00/80←\←]4;2;rgb:00/80/00←\←
]4;6;rgb:00/80/80←\←]4;1;rgb:80/00/00←\←]4;5;rgb:80/00/80←\←]4;3;rgb:80/80/00←\←]4;7;rgb:c0/c0/c0←\←]4;8;rgb:80/80/80←\←
]4;12;rgb:00/00/ff←\←]4;10;rgb:00/ff/00←\←]4;14;rgb:00/ff/ff←\←]4;9;rgb:ff/00/00←\←]4;13;rgb:ff/00/ff←\←]4;11;rgb:ff/ff/
00←\←]4;15;rgb:ff/ff/ff←\←]4;16;rgb:00/00/00←\←]4;17;rgb:00/00/5f←\←]4;18;rgb:00/00/87←\←]4;19;rgb:00/00/af←\←]4;20;rgb:
00/00/d7←\←]4;21;rgb:00/00/ff←\←]4;22;rgb:00/5f/00←\←]4;23;rgb:00/5f/5f←\←]4;24;rgb:00/5f/87←\←]4;25;rgb:00/5f/af←\←]4;2
6;rgb:00/5f/d7←\←]4;27;rgb:00/5f/ff←\←]4;28;rgb:00/87/00←\←]4;29;rgb:00/87/5f←\←]4;30;rgb:00/87/87←\←]4;31;rgb:00/87/af←
\←]4;32;rgb:00/87/d7←\←]4;33;rgb:00/87/ff←\←]4;34;rgb:00/af/00←\←]4;35;rgb:00/af/5f←\←]4;36;rgb:00/af/87←\←]4;37;rgb:00/
af/af←\←]4;38;rgb:00/af/d7←\←]4;39;rgb:00/af/ff←\←]4;40;rgb:00/d7/00←\←]4;41;rgb:00/d7/5f←\←]4;42;rgb:00/d7/87←\←]4;43;r
gb:00/d7/af←\←]4;44;rgb:00/d7/d7←\←]4;45;rgb:00/d7/ff←\←]4;46;rgb:00/ff/00←\←]4;47;rgb:00/ff/5f←\←]4;48;rgb:00/ff/87←\←]
4;49;rgb:00/ff/af←\←]4;50;rgb:00/ff/d7←\←]4;51;rgb:00/ff/ff←\←]4;52;rgb:5f/00/00←\←]4;53;rgb:5f/00/5f←\←]4;54;rgb:5f/00/
87←\←]4;55;rgb:5f/00/af←\←]4;56;rgb:5f/00/d7←\←]4;57;rgb:5f/00/ff←\←]4;58;rgb:5f/5f/00←\←]4;59;rgb:5f/5f/5f←\←]4;60;rgb:
5f/5f/87←\←]4;61;rgb:5f/5f/af←\←]4;62;rgb:5f/5f/d7←\←]4;63;rgb:5f/5f/ff←\←]4;64;rgb:5f/87/00←\←]4;65;rgb:5f/87/5f←\←]4;6
6;rgb:5f/87/87←\←]4;67;rgb:5f/87/af←\←]4;68;rgb:5f/87/d7←\←]4;69;rgb:5f/87/ff←\←]4;70;rgb:5f/af/00←\←]4;71;rgb:5f/af/5f←
\←]4;72;rgb:5f/af/87←\←]4;73;rgb:5f/af/af←\←]4;74;rgb:5f/af/d7←\←]4;75;rgb:5f/af/ff←\←]4;76;rgb:5f/d7/00←\←]4;77;rgb:5f/
d7/5f←\←]4;78;rgb:5f/d7/87←\←]4;79;rgb:5f/d7/af←\←]4;80;rgb:5f/d7/d7←\←]4;81;rgb:5f/d7/ff←\←]4;82;rgb:5f/ff/00←\←]4;83;r
gb:5f/ff/5f←\←]4;84;rgb:5f/ff/87←\←]4;85;rgb:5f/ff/af←\←]4;86;rgb:5f/ff/d7←\←]4;87;rgb:5f/ff/ff←\←]4;88;rgb:87/00/00←\←]
4;89;rgb:87/00/5f←\←]4;90;rgb:87/00/87←\←]4;91;rgb:87/00/af←\←]4;92;rgb:87/00/d7←\←]4;93;rgb:87/00/ff←\←]4;94;rgb:87/5f/
00←\←]4;95;rgb:87/5f/5f←\←]4;96;rgb:87/5f/87←\←]4;97;rgb:87/5f/af←\←]4;98;rgb:87/5f/d7←\←]4;99;rgb:87/5f/ff←\←]4;100;rgb
:87/87/00←\←]4;101;rgb:87/87/5f←\←]4;102;rgb:87/87/87←\←]4;103;rgb:87/87/af←\←]4;104;rgb:87/87/d7←\←]4;105;rgb:87/87/ff←
\←]4;106;rgb:87/af/00←\←]4;107;rgb:87/af/5f←\←]4;108;rgb:87/af/87←\←]4;109;rgb:87/af/af←\←]4;110;rgb:87/af/d7←\←]4;111;r
gb:87/af/ff←\←]4;112;rgb:87/d7/00←\←]4;113;rgb:87/d7/5f←\←]4;114;rgb:87/d7/87←\←]4;115;rgb:87/d7/af←\←]4;116;rgb:87/d7/d
7←\←]4;117;rgb:87/d7/ff←\←]4;118;rgb:87/ff/00←\←]4;119;rgb:87/ff/5f←\←]4;120;rgb:87/ff/87←\←]4;121;rgb:87/ff/af←\←]4;122
;rgb:87/ff/d7←\←]4;123;rgb:87/ff/ff←\←]4;124;rgb:af/00/00←\←]4;125;rgb:af/00/5f←\←]4;126;rgb:af/00/87←\←]4;127;rgb:af/00
/af←\←]4;128;rgb:af/00/d7←\←]4;129;rgb:af/00/ff←\←]4;130;rgb:af/5f/00←\←]4;131;rgb:af/5f/5f←\←]4;132;rgb:af/5f/87←\←]4;1
33;rgb:af/5f/af←\←]4;134;rgb:af/5f/d7←\←]4;135;rgb:af/5f/ff←\←]4;136;rgb:af/87/00←\←]4;137;rgb:af/87/5f←\←]4;138;rgb:af/
87/87←\←]4;139;rgb:af/87/af←\←]4;140;rgb:af/87/d7←\←]4;141;rgb:af/87/ff←\←]4;142;rgb:af/af/00←\←]4;143;rgb:af/af/5f←\←]4
;144;rgb:af/af/87←\←]4;145;rgb:af/af/af←\←]4;146;rgb:af/af/d7←\←]4;147;rgb:af/af/ff←\←]4;148;rgb:af/d7/00←\←]4;149;rgb:a
f/d7/5f←\←]4;150;rgb:af/d7/87←\←]4;151;rgb:af/d7/af←\←]4;152;rgb:af/d7/d7←\←]4;153;rgb:af/d7/ff←\←]4;154;rgb:af/ff/00←\←
]4;155;rgb:af/ff/5f←\←]4;156;rgb:af/ff/87←\←]4;157;rgb:af/ff/af←\←]4;158;rgb:af/ff/d7←\←]4;159;rgb:af/ff/ff←\←]4;160;rgb
:d7/00/00←\←]4;161;rgb:d7/00/5f←\←]4;162;rgb:d7/00/87←\←]4;163;rgb:d7/00/af←\←]4;164;rgb:d7/00/d7←\←]4;165;rgb:d7/00/ff←
\←]4;166;rgb:d7/5f/00←\←]4;167;rgb:d7/5f/5f←\←]4;168;rgb:d7/5f/87←\←]4;169;rgb:d7/5f/af←\←]4;170;rgb:d7/5f/d7←\←]4;171;r
gb:d7/5f/ff←\←]4;172;rgb:d7/87/00←\←]4;173;rgb:d7/87/5f←\←]4;174;rgb:d7/87/87←\←]4;175;rgb:d7/87/af←\←]4;176;rgb:d7/87/d
7←\←]4;177;rgb:d7/87/ff←\←]4;178;rgb:d7/af/00←\←]4;179;rgb:d7/af/5f←\←]4;180;rgb:d7/af/87←\←]4;181;rgb:d7/af/af←\←]4;182
;rgb:d7/af/d7←\←]4;183;rgb:d7/af/ff←\←]4;184;rgb:d7/d7/00←\←]4;185;rgb:d7/d7/5f←\←]4;186;rgb:d7/d7/87←\←]4;187;rgb:d7/d7
/af←\←]4;188;rgb:d7/d7/d7←\←]4;189;rgb:d7/d7/ff←\←]4;190;rgb:d7/ff/00←\←]4;191;rgb:d7/ff/5f←\←]4;192;rgb:d7/ff/87←\←]4;1
93;rgb:d7/ff/af←\←]4;194;rgb:d7/ff/d7←\←]4;195;rgb:d7/ff/ff←\←]4;196;rgb:ff/00/00←\←]4;197;rgb:ff/00/5f←\←]4;198;rgb:ff/
00/87←\←]4;199;rgb:ff/00/af←\←]4;200;rgb:ff/00/d7←\←]4;201;rgb:ff/00/ff←\←]4;202;rgb:ff/5f/00←\←]4;203;rgb:ff/5f/5f←\←]4
;204;rgb:ff/5f/87←\←]4;205;rgb:ff/5f/af←\←]4;206;rgb:ff/5f/d7←\←]4;207;rgb:ff/5f/ff←\←]4;208;rgb:ff/87/00←\←]4;209;rgb:f
f/87/5f←\←]4;210;rgb:ff/87/87←\←]4;211;rgb:ff/87/af←\←]4;212;rgb:ff/87/d7←\←]4;213;rgb:ff/87/ff←\←]4;214;rgb:ff/af/00←\←
]4;215;rgb:ff/af/5f←\←]4;216;rgb:ff/af/87←\←]4;217;rgb:ff/af/af←\←]4;218;rgb:ff/af/d7←\←]4;219;rgb:ff/af/ff←\←]4;220;rgb
:ff/d7/00←\←]4;221;rgb:ff/d7/5f←\←]4;222;rgb:ff/d7/87←\←]4;223;rgb:ff/d7/af←\←]4;224;rgb:ff/d7/d7←\←]4;225;rgb:ff/d7/ff←
\←]4;226;rgb:ff/ff/00←\←]4;227;rgb:ff/ff/5f←\←]4;228;rgb:ff/ff/87←\←]4;229;rgb:ff/ff/af←\←]4;230;rgb:ff/ff/d7←\←]4;231;r
gb:ff/ff/ff←\←]4;232;rgb:08/08/08←\←]4;233;rgb:12/12/12←\←]4;234;rgb:1c/1c/1c←\←]4;235;rgb:26/26/26←\←]4;236;rgb:30/30/3
0←\←]4;237;rgb:3a/3a/3a←\←]4;238;rgb:44/44/44←\←]4;239;rgb:4e/4e/4e←\←]4;240;rgb:58/58/58←\←]4;241;rgb:62/62/62←\←]4;242
;rgb:6c/6c/6c←\←]4;243;rgb:76/76/76←\←]4;244;rgb:80/80/80←\←]4;245;rgb:8a/8a/8a←\←]4;246;rgb:94/94/94←\←]4;247;rgb:9e/9e
/9e←\←]4;248;rgb:a8/a8/a8←\←]4;249;rgb:b2/b2/b2←\←]4;250;rgb:bc/bc/bc←\←]4;251;rgb:c6/c6/c6←\←]4;252;rgb:d0/d0/d0←\←]4;2
53;rgb:da/da/da←\←]4;254;rgb:e4/e4/e4←\←]4;255;rgb:ee/ee/ee←\C^CC^C^^CC^CC^C^C^CC^C^C^CC^CC
# Similar for npm/npx/corepack

Expected behavior

  • Shims should work even when executed when the shim directory is current

Desktop (please complete the following information):

  • OS: Windows 11 23H2 Home 10.0.22635.4367
  • Arch: x64
  • NVM Desktop Version: 4.0.1
@iki iki added the bug Something isn't working label Oct 16, 2024
@1111mp
Copy link
Owner

1111mp commented Oct 17, 2024

On Windows, when executing a command, the system searches for executable files in the following order:

  • Current directory: It first checks the current directory for the executable.
  • System PATH environment variable: Then it searches the directories listed in the PATH environment variable, in order.

This means if there is an executable with the same name in the current directory, it will be used first.

As for node's shim, it will splice a system environment variable and assign it to the newly created child process to execute the user's command. However, since the node.exe in the current folder has a higher priority, the system still uses the node.exe file in the current file when the child process is executed. Therefore, it will fall into an infinite loop.

pub(super) fn command(exe: &OsStr, args: &[OsString]) -> Result<ExitStatus> {
    let path = ENV_PATH
        .clone()
        .ok_or_else(|| anyhow!("command not found: {:?}", exe))?;

    let status = CommandTool::create_command(exe)
        .env("PATH", path)
        .args(args)
        .status()?;

    Ok(status)
}

I think this is in line with how the node.exe shim works. But for this question, I think users should be able to realize why this happens. Users can control it themselves to avoid executing the command directly in the "%HOMEPATH%\.nvmd\bin" directory.

@iki
Copy link
Author

iki commented Oct 20, 2024

@1111mp yes, that seems to be the cause.

What about running the exe with full path, like %UserProfile%\.nvmd\versions\<selectedVersion>\<command>.exe?

@1111mp
Copy link
Owner

1111mp commented Oct 25, 2024

@1111mp yes, that seems to be the cause.

What about running the exe with full path, like %UserProfile%\.nvmd\versions\<selectedVersion>\<command>.exe?

After testing, using the complete %UserProfile%\.nvmd\versions\<selectedVersion>\<command>.exe path will not result in an infinite loop.

%UserProfile%\.nvmd\versions\22.2.0\node.exe --version

@iki
Copy link
Author

iki commented Nov 9, 2024

Yes, however the point actually was: What about running the exe with full path within the shim code above. That would avoid any possible infinite loop in the shim as well. WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants