FWeinb / electron-screenshot-service

Take screenshots using electron
MIT License
141 stars 26 forks source link

Hundreds of electron process #12

Closed asafyish closed 8 years ago

asafyish commented 8 years ago

Hi,

After using and restarting many times, I see that we have hundreds of electron process, maybe it will help to use something like https://www.npmjs.com/package/child-killer to ensure process are dead when the parent process dies.

FWeinb commented 8 years ago

That sounds very strange. Is your application exited gracefully or crashing?

asafyish commented 8 years ago

We are using pm2 (https://github.com/Unitech/pm2) and doing pm2 restart. I am not exactly sure how it kill the process.

FWeinb commented 8 years ago

It looks like pm2 is sending a SIGINT to the process. So you might want to add the screenshot.close() call like this:

process.on('SIGINT', function() {
  screenshot.close();
});
asafyish commented 8 years ago

Tried that... no luck. we still have hundreds of process. BTW, we are using scale to 20. Is that related ?

FWeinb commented 8 years ago

Scale 20 should just scale the amount to 20 processes (so approx. 20 electron + 20 electron helpers) But there could be more than 1 helper per site.

asafyish commented 8 years ago

Maybe using something like https://npmjs.org/package/child-killer when spawning the process could help ?

FWeinb commented 8 years ago

This sounds really strange. Is the callback called by pm2? child-killer is polling every 100ms for each process, I would rather not do that. Which OS are you using?

asafyish commented 8 years ago

We are using Ubuntu 15.04. What solved the problem is listening fro SIGTERM:

process.on('SIGTERM', function () {
        screenshot.close();

        setTimeout(function() {
            process.exit(0);
        }, 1000)
    });
FWeinb commented 8 years ago

Glad you found a solution.