skip to Main Content

I’m hosting a website on a web host using a nodejs application (expressjs, request, etc.). The web host has an apache terminal from where I can call node app.js & or forever start app.js and the app runs fine.
However, once the terminal is closed, the number of processes being used balloons to about 30, meaning that the next time I open the terminal, instead of being greeted with [hostname@server ~] $ I instead get:

bash: fork: retry: No child processes
bash: fork: retry: No child processes
bash: fork: retry: No child processes
bash: fork: retry: No child processes
bash: fork: Resource temporarily unavailable
bash-4.2$

Somehow I believe a fork bomb is being created, and I can’t seem to figure out where or why? I’m not using fork() anywhere, and if I use forever to start my app, the logs show no signs of errors or new processes being created.

When this happens, I can’t use any terminal commands half the time, until I manage to pkill/pgrep.

I tried calling bash-4.2$ top, and got this:

top - 13:41:13 up 71 days, 20:57, 0 users, load average: 1.82, 1.81, 1.72
Tasks: 14 total, 1 running, 2 sleeping, 11 stopped, 0 zombie
%Cpu(s): 11.7 us, 2.7 sy, 0.1 ni, 85.5 id, 0.1 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 41034544 total, 2903992 free, 6525792 used, 31604760 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 28583704 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1001511 xxxxxxxx 20 0 11880 3692 1384 S 0.0 0.0 0:00.02 bash
1001578 xxxxxxxx 20 0 11880 2840 524 T 0.0 0.0 0:00.00 bash
1001598 xxxxxxxx 20 0 11880 2672 348 T 0.0 0.0 0:00.00 bash
1001599 xxxxxxxx 20 0 11880 2896 524 T 0.0 0.0 0:00.00 bash
1001600 xxxxxxxx 20 0 11880 2720 396 T 0.0 0.0 0:00.00 bash
1001607 xxxxxxxx 20 0 11880 2928 532 T 0.0 0.0 0:00.00 bash
1001613 xxxxxxxx 20 0 11880 2964 532 T 0.0 0.0 0:00.00 bash
1001618 xxxxxxxx 20 0 11880 2780 348 T 0.0 0.0 0:00.00 bash
1001619 xxxxxxxx 20 0 12012 3024 544 T 0.0 0.0 0:00.00 bash
1001620 xxxxxxxx 20 0 11880 2804 372 T 0.0 0.0 0:00.00 bash
1001651 xxxxxxxx 20 0 12012 2836 352 T 0.0 0.0 0:00.00 bash
1001653 xxxxxxxx 20 0 12016 3392 896 T 0.0 0.0 0:00.00 bash
1004463 xxxxxxxx 20 0 9904 1840 1444 S 0.0 0.0 0:00.00 bash
1005200 xxxxxxxx 20 0 56364 1928 1412 R 0.0 0.0 0:00.00 top

Which looks like somehow bash processes are being repeatedly made?

My actual nodejs app.js is a typical expressjs web app, with code such as (shortened example code):

var app = express();

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

app.post('/profile', function(req,res){
    "use strict";
    var id = req.query.id;
    con.query("SELECT * FROM xxxxxxx WHERE xxxxx=" + id, function(err,result){
        res.send(result);               
    }); 
});

app.get('*', function(req, res) {
    "use strict";
    res.redirect('/404.html');
});

console.log('Listening on 8080');
app.listen(8080);

Any ideas on why this issue is occurring? I’m relatively new to node so any help is appreciated, and apologies if any noob mistakes have been made.

2

Answers


  1. Chosen as BEST ANSWER

    So it seems that the problem is actually stemming from my ~/.bashrc file which contains these lines:

    # User specific aliases and functions
    
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
    [ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
    

    If these lines are commented out, then the problem ceases to occur. However I obviously can't use node commands because nvm isn't started.

    Somehow that code is looping creating multiple bash instances whenever the terminal is accessed.


  2. Do you use Visual Code Extension "Visual Studio IntelliCode" ?
    If yes try removing it. No more "Fork Bombs". Do not ask me why. I only know that after 3 hours hitting my head, i finally found a way to stop node forking processes.

    CONTEXT: Visual Code on Windows, accessing a VPS with Ubuntu Server via Remote SSH Plugin at VS Code. NVM installed. If i remove NVM and/or remove the export line at ~/.bashrc nothing happens. Thousands of Zumbi processes are created. I remove Visual Studio IntelliCode Extension and Voilá! All OK.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search