0

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?

systemdebt
  • 4,589
  • 10
  • 55
  • 116
  • Which version of node? Also possibly this:http://stackoverflow.com/questions/16840623/how-to-debug-node-js-child-forked-process – jmunsch Feb 24 '16 at 12:11
  • But as you might see, I have already forked the child process on a new port. It's version 4.3.0 – systemdebt Feb 24 '16 at 12:17
  • I was having major issues the other day with 4.3.0 using `node debug anotherthing.js` kept crashing, i havent checked the changelogs so that issue may have been fixed in 4.3.1. I downgraded to 4.2.6 and the crashing stopped, just something to check. – jmunsch Feb 24 '16 at 12:21
  • @jm_____ : Could you please check the update? – systemdebt Feb 25 '16 at 08:11
  • I guess I don't understand why the task is being forked? Why not just require it and run it in the same process? What is bgTask doing? – jmunsch Feb 25 '16 at 19:02
  • It behaves the same way in both the cases. I forked it one first place only to avoid this behaviour but it continued anyway. @jm_____ – systemdebt Mar 05 '16 at 09:34

0 Answers0