forked child process in node.js throws channel closed error on a post/put API call

53 views
Skip to first unread message

simran kaur

unread,
Feb 25, 2016, 10:59:50 AM2/25/16
to nodejs
I have a script file in Node js with a function that recursively calls itself after sometime outs. 

This function sends out a "message" to which parent is listening.

This parent is nothing but a REST api with basic CRUD operations. 

In this file, this is what forking part looks like:

    var myBgTask = require('child_process').fork('./server/api/thing/bgTask.js', [], { execArgv: ['--debug=5859']});
    myBgTask.on('message', function(data){
      //DO SOMETHING
    })

Now, when from my angular code, I make a request to update the database, somehow the child process gets interrupted and throws Channel closed error at this line:

    process.send({
        name: randomThing,
        readByUser: false 
       }, function(err){
        console.log("error", err)
        if(!err)
             setTimeout(autoCreate, randomNumb * 1000);
    
       });

and thus my server stops and I never am able to make http `post`/`put` calls. 

Strange part is that it throws error only when I am making `post` or `put` calls and never with `get` calls. 

I have been trying to debug this but have not been able to find out what the problem is. Can I get some help here on this?

Reply all
Reply to author
Forward
0 new messages