I'm used to catching SIGTERM and SIGINT on my node.js scripts. I use process.on('SIGTERM',function(){ <stuff> }); and I can call other functions that revert some changes before closing, or just print "you pressed ^C !", do nothing else and the script keeps running if I want to.

It doesn't work since I added web3. When I press ^C is pauses the script and I can't do anything. I have to kill the process by pid on another terminal.

The most blocking operation is accessing data from a contract loaded in the beginning of the script. Something like:

valueA = mycontract.mappingA(key);
valueB = mycontract.mappingB(key);

This operation takes about 250ms and is repeated a lot of times, so I'm almost sure the script is on that part when I press ^C.

I tried putting that part in a try/catch construct but it still won't do what is on the catch part.

Why is this happening ? Can I make it work or should I stop catching SIGINT and SIGTERM ?

If you need extra info, on my process list (ps aux), under node myscript.js there is a script called [nodejs] <defunct>. The "state" part indicates node myscript is Rl+ (Running or runnable, multi-threaded, on the foreground process group) and [nodejs] <defunct> is Z+ (defunct/zombie, on the foreground).

  • Do you have an event listener or filter in your code? That's always on until you .stopWatching(). Jan 18 '17 at 16:41
  • I don't think so. I didn't use stopWatching() either. What is always on ? Jan 18 '17 at 16:47
  • When you filter, web3 will regularly ping the RPC node for updates. It never gives back the hand so NodeJs never considers it finished. Jan 18 '17 at 17:11
  • @XavierLeprêtreB9lab If I understand correctly, if I don't filter I shouldn't have this problem ? Could it be set automatically, as an option on geth for example ? Jan 18 '17 at 17:19
  • Correct, you need to explicitly filter for it to happen. Jan 18 '17 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.