Nvm: "nvm use" gets stuck in inifinite loop causing a fork bomb

Created on 28 May 2019  路  24Comments  路  Source: nvm-sh/nvm

  • Operating system and version:
    Linux bash 4.2 terminal on web host

  • nvm debug output:
    ```nvm --version: v0.34.0
    $SHELL: /bin/bash
    $SHLVL: 1
    $HOME: /home/domainnamehere
    $NVM_DIR: '$HOME/.nvm'
    $PATH: /usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin:/opt/bin:/opt/cpanel/composer/bin:$HOME/.local/bin:$HOME/bin
    $PREFIX: ''
    $NPM_CONFIG_PREFIX: ''
    $NVM_NODEJS_ORG_MIRROR: ''
    $NVM_IOJS_ORG_MIRROR: ''
    shell version: 'GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)'
    uname -a: 'Linux 3.10.0-962.3.2.lve1.5.24.9.el7.x86_64 #1 SMP Wed Feb 13 08:24:50 EST 2019 x86_64 x86_64 x86_64 GNU/Linux'
    curl: /bin/curl, curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.36 zlib/1.2.7 libidn/1.28 libssh2/1.4.3
    wget: /bin/wget, GNU Wget 1.14 built on linux-gnu.
    git: /usr/local/cpanel/3rdparty/lib/path-bin/git, git version 2.19.1
    grep: alias grep='grep --color=auto'
    /bin/grep (grep --color=auto), grep (GNU grep) 2.20
    awk: /bin/awk, GNU Awk 4.0.2
    sed: /bin/sed, sed (GNU sed) 4.2.2
    cut: /bin/cut, cut (GNU coreutils) 8.22
    basename: /bin/basename, basename (GNU coreutils) 8.22
    rm: /bin/rm, rm (GNU coreutils) 8.22
    mkdir: /bin/mkdir, mkdir (GNU coreutils) 8.22
    xargs: /bin/xargs, xargs (GNU findutils) 4.5.11

(Omitted the last lines as nvm is being started with --no-use)

- `nvm ls` output:
```        v12.3.1```

- How did you install `nvm`? (e.g. install script in readme, Homebrew):
Using the install script `curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash`

- What steps did you perform?
 I've added --no-use to the end of my .bashrc so that I can at least access the terminal before the issue occurs, but once I have terminal access I tried calling `nvm use default` to load node 

- What happened?
the number of resources being used on the server ballooned to the point where I was only getting `bash: fork: retry: no child processes` and `bash: fork: retry: resource temporarily unavailable`

- What did you expect to happen?
nvm use node without creating a fork bomb/depleting all server resources. The issue doesn't occur when `nvm use` isn't called, or if I don't let nvm start at all

- Is there anything in any of your profile files (`.bashrc`, `.bash_profile`, `.zshrc`, etc) that modifies the `PATH`?
.bash_profile contains the following:

User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH
```

bugs pull request wanted

All 24 comments

What's the full output of nvm ls?

That is the full output:

[hostname@serv ~]$ nvm ls
        v12.3.1

Hmm, usually it also includes nvm alias. What's nvm alias print out?

nvm alias gives:
```[hostname@srv ~]$ nvm alias
default -> stable (-> v12.3.1)
/home/*/.nvm/nvm.sh: fork: retry: No child processes
/home/
/.nvm/nvm.sh: fork: retry: No child processes
/home/
/.nvm/nvm.sh: fork: retry: No child processes
/home/
/.nvm/nvm.sh: fork: retry: No child processes
/home/
/.nvm/nvm.sh: fork: retry: No child processes
/home/
/.nvm/nvm.sh: fork: retry: No child processes
/home/
/.nvm/nvm.sh: fork: retry: No child processes
/home/
*/.nvm/nvm.sh: fork: retry: No child processes
(etc.)

If you look in $NVM_DIR/alias, what files are in there, and what are their contents?

.nvm/alias:

[lts]
default

.nvm/alias/lts:

*
argon
boron
carbon
dubnium

.nvm/alias/default contains:
stable

.nvm/alias/* contains:
lts/dubnium

.nvm/alias/argon contains:
v4.9.1

.nvm/alias/boron contains:
v6.17.1

.nvm/alias/carbon contains:
v8.16.0

.nvm/alias/dubnium contains:
v10.15.3

I wonder if the * alias is causing problems - if you delete that file, and then run nvm alias, what happens? (note that any nvm ls-remote will recreate it)

Deleted *, still received similar behaviour:

[hostname@srv ~]$ nvm alias
default -> stable (-> v12.3.1)
/home/******/.nvm/nvm.sh: fork: retry: Resource temporarily unavailable
/home/******/.nvm/nvm.sh: fork: retry: No child processes
/home/******/.nvm/nvm.sh: fork: retry: Resource temporarily unavailable
/home/******/.nvm/nvm.sh: fork: retry: No child processes
/home/******/.nvm/nvm.sh: fork: retry: Resource temporarily unavailable
/home/******/.nvm/nvm.sh: fork: retry: No child processes
...

I'm super confused :-/ maybe also try deleting the alias/lts dir?

Deleted this alias/lts dir but unfortunately still observing the same behaviour. Can't seem to figure out at all why though, no idea where the loop is occurring.

I opened 2 terminal windows, 1 running top and the other in which I called nvm alias and here is what happened
top before:

top - 16:38:17 up 73 days, 23:54,  0 users,  load average: 2.48, 2.92, 3.14
Tasks:   3 total,   1 running,   2 sleeping,   0 stopped,   0 zombie
%Cpu(s): 11.3 us, 10.0 sy,  0.1 ni, 78.5 id,  0.1 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 41034544 total,  5257852 free,  6415280 used, 29361412 buff/cache
KiB Swap:        0 total,        0 free,        0 used. 28726240 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
1040322 ******  20   0   11756   3668   1364 S   0.0  0.0   0:00.02 bash
1040556 ******  20   0   56352   1916   1416 R   0.0  0.0   0:00.00 top

top after:

top - 16:39:17 up 73 days, 23:55,  0 users,  load average: 2.99, 2.99, 3.15
Tasks:  31 total,   1 running,  30 sleeping,   0 stopped,   0 zombie
%Cpu(s): 17.1 us,  9.0 sy,  0.1 ni, 73.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 41034544 total,  5170696 free,  6646252 used, 29217596 buff/cache
KiB Swap:        0 total,        0 free,        0 used. 28482268 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
1040322 ******  20   0   11756   3668   1364 S   0.0  0.0   0:00.02 bash
1040556 ******  20   0   56352   1916   1416 R   0.0  0.0   0:00.02 top
1040605 ******  20   0   11756   3760   1440 S   0.0  0.0   0:00.03 bash
1041406 ******  20   0   11756   2768    448 S   0.0  0.0   0:00.00 bash
1041407 ******  20   0   23120    752    644 S   0.0  0.0   0:00.00 sort
1041409 ******  20   0   11756   2832    512 S   0.0  0.0   0:00.00 bash
1041410 ******  20   0   11756   2716    396 S   0.0  0.0   0:00.00 bash
1041411 ******  20   0   11756   2716    396 S   0.0  0.0   0:00.00 bash
1041412 ******  20   0   11756   2844    524 S   0.0  0.0   0:00.00 bash
1041414 ******  20   0   11756   2844    524 S   0.0  0.0   0:00.00 bash
1041428 ******  20   0   11756   2660    340 S   0.0  0.0   0:00.00 bash
1041430 ******  20   0   11756   2660    340 S   0.0  0.0   0:00.00 bash
1041431 ******  20   0   11756   2848    528 S   0.0  0.0   0:00.00 bash
1041432 ******  20   0   11756   2676    356 S   0.0  0.0   0:00.00 bash
1041434 ******  20   0   11756   2836    516 S   0.0  0.0   0:00.00 bash
1041435 ******  20   0   11756   2724    404 S   0.0  0.0   0:00.00 bash
1041436 ******  20   0   11756   2848    528 S   0.0  0.0   0:00.00 bash

It seems a bunch of new bash instances are being created somehow.

Could you try set -x; nvm alias?

Here is the result: https://pastebin.com/q6rm70P8
(Pastebin link as it is quite long)

Thanks, and set -x; nvm_list_aliases?

New paste of set -x; nvm_list_aliases: https://pastebin.com/8pHEPJmn

and NVM_CURRENT="$(nvm_ls_current)" nvm_print_alias_path "$NVM_DIR/alias" "$NVM_DIR/alias/lts/*"?

That returns nothing, presumably because the .nvm/alias/lts folder is still empty?

On a side note, I've found that this issue only occurs when there is already a node running on the server. If there is no node currently running, calling nvm use default works as intended and returns Now using node v12.3.1 (npm v6.9.0) but it's only if there is a node running that the issue occurs and it crashes out. (This occurs both if the node is being run with node app.js & or forever start app.js)

when you say "a node running" - you mean, an open node process? Do you have a system node?

I'm using NodeJS to host my website on my webhost with expressjs; a simple app along the lines of:

var app = express();
app.use(express.static('..//'))
   .use(cors())
   .use(cookieParser());

//code

app.get('*', function(req, res) {
    "use strict";
    res.redirect('/404.html');
});
console.log('Listening on 8080');
app.listen(8080);

Which is how I present my site on my domain. As such I need to run the app from terminal for the site to be available - so if the above is app.js I can use either node app.js & or forever start app.js to perpetually run the app in the background.

Edit to be more clear:
I can access terminal fine and use nvm/node/forever to start the app, but once the app is running I encounter the issue discussed in this thread the next time I try and access the terminal.

forever, i can see causing problems if the node it's re-invoking gets changed out from under it - but having node running in the background shouldn't, as far as i know.

Just confirmed and the issue occurs both with node & and forever. Although theoretically the node shouldn鈥檛 be reinvoked, it should just continue to run in the background while nvm is started in the new bash/terminal instance? (I may be mistaken here as I am still relatively novice in this area)

To clarify - are you running node & in the same shell as the bombing nvm use? or in a different tab?

nvm is a sourced shell function; it doesn't create a new shell instance.

In a different tab - essentially the process is:

  • Open terminal on web host
  • See [hostname@srv ~]$ as expected
  • Call nvm use default (works fine)
  • Either use node app.js & or forever start app.js to run node script
  • exit and close terminal window
  • Later, open terminal again via the web host page
  • See [hostname@srv ~]$ as expected
  • Try to call nvm use default again
  • This is where the issue occurs and the fork: retry: No child processes spam begins

It's a weird issue so I'm trying to be as clear as possible but let me know if you still need more info.

Thanks, i really appreciate the back and forth.

I don鈥檛 know enough about fork, tbh, to have any idea how this would happen :-/

All good, thanks for persisting. I've got a minor workaround at the moment which is just to add --no-use onto .bashrc and pkill -f node before calling nvm use default which avoids the error. Not exactly best practice and can be annoying to always have to restart processes but it works for now until I can find the root cause of the problem.

Was this page helpful?
0 / 5 - 0 ratings