3
votes

I'm forking child process and for some odd reason each time the child process exits with the status code 8. I did bunch of googling trying to figure out what is status code 8 and what might be causing this strange behavior in Ubuntu but had no luck. I learned that Node.js doesn't even use exit status code 8 so I'm pretty confident that its not the V8. I tried executing the same code on a different but identical Ubuntu server and it worked fine. Just to note, I'm using a load balancer on this server. I'm not sure what could be causing this issue.

Here are the specs :

  • Node : v0.10.25
  • Distributor ID: Ubuntu
  • Description: Ubuntu 14.04
  • LTS Release: 14.04

This is the forked child process (like i said its very minimum)


    process.on('message', function(data) {
        console.log('TEST BOT SAYS HELLO ' + process.pid)

        var fs = require('fs')
        fs.writeFile('message.txt', 'abc', function(err, data) {
            if (err) {
                return console.log(err);
            }
            console.log(data);
        });

    });

Edit: There is not other error in the stack trace. Any clues to figure this out would help!

Here is how the child process is launched :



        function testChildProcess() {
            console.log('testing child process')
            var testBot = childProcess.fork(require.resolve("./../../bots/testBot"));

            testBot.send({
                data: 'hello'
            });

            testBot.on('exit', function(code, other) {
                console.log('Child process exited with exit code ' + code + ' other ');

            });
            testBot.on('error', function(code) {
                console.log('Child process ERRED with exit code ' + code);
                return nextTracker();
            });
        }
    testChildProcess()

Addition : The application is ran using https://github.com/yyx990803/pod which uses pm2 to in the background

https://github.com/Unitech/pm2 to launch the application as a daemon.

I tested out spawning child process and spawning a child process works just fine...

child.js


    var test = function() {
        console.log('TEST BOT SAYS HELLO ' + process.pid)

        var fs = require('fs')
        fs.writeFile('./message.txt', 'abc', function(err, data) {
            if (err) {
                return console.log(err);
            }
            console.log(data);
        });

    }
    test();

parent.js



function testChildProcess() {
console.log(process.cwd());

        var ls = childProcess.exec('node '+process.cwd()+'/bots/testBot', function(error, stdout, stderr) {
            if (error) {
                console.log(error.stack);
                console.log('Error code: ' + error.code);
                console.log('Signal received: ' + error.signal);
            }
            console.log('stdout: ' + stdout);
            console.log('stderr: ' + stderr);

        });

        ls.on('exit', function(code) {
            console.log('Child process exited with exit code ' + code);
        });
    }

SOLUTION : Incase someone else gets this issue. I managed to get around by having silent set to true.


var testBot = childProcess.fork(require.resolve("./../../bots/testBot"),[],{silent:true});


1
Probably errno 8: #define ENOEXEC 8 /* Exec format error */Joe
How are you launching your child process?Joe
Hey Joe, thank you for any help. I updated the comment with the script I use to launch the child process.Milos Bejda
What are your permissions on testBot on the working and non-working servers?Joe
Joe, out of desperation I done chmod -R 777 ./* on the entire root directory of the application on the working server. Still getting the mysterious exit status code 8.Milos Bejda

1 Answers

-3
votes

SOLUTION: In case someone else gets this issue, I managed to get around by having silent set to true.

var testBot = childProcess.fork(require.resolve("./../../bots/testBot"),[],{silent:true});