1

why my function "SIGINT" works two times? i want to application to close after time, i use function with recursion, but i see two results in a console 'SIGINT signal received.' if i don't use recursion, i have only one result

async function checkActiveProcess(start_time){
   active_set.status = 'stop'
   let now_data = new Date().getTime();
   if (now_data - start_time > 5000){
      if (active_set.counter > 0){
        active_set.counter -= 1
        console.info(active_set.counter)
        setTimeout(checkActiveProcess, 5000, start_time)
      } else {
        console.log('All ok')
        process.exit(0);
      }
    } else {
      console.log(`Sorry, not enough time`)
      process.exit(0)
    }
  }


  process.on('SIGINT', () => {
    const start_time = new Date().getTime();
    console.info('SIGINT signal received.');
    setTimeout(checkActiveProcess, process.env.TIME/5, start_time)
  });

i am running application in centos and when i do ctrl+C, in console i see next:

SIGINT signal received. 
SIGINT signal received. 
4 
3 
2 
1 
0

like i understand, function work two times, how to fix it?

  • 1
    Does this answer your question? [Node and NPM Running script and Ctrl-C triggers SIGINT twice](https://stackoverflow.com/questions/54722158/node-and-npm-running-script-and-ctrl-c-triggers-sigint-twice) – Justinas Oct 28 '20 at 12:15
  • no, i use "node index.js" i don't use "npm start" – Natasha Grosella Oct 30 '20 at 08:53

0 Answers0