peerigon / phridge

A bridge between node and PhantomJS
The Unlicense
519 stars 50 forks source link

phridge.dispose causes EPIPE error after SIGINT #34

Closed SystemParadox closed 8 years ago

SystemParadox commented 9 years ago

test program:

var phridge = require('phridge');
var ph = phridge.spawn();
ph.then(function (ph) {
    console.log('phantomJS started');
});
process.on('SIGINT', function () {
    phridge.disposeAll().then(function () {
        console.log('phantomJS closed');
        process.exit();
    });
});

output:

phantomJS started
^C
events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: write EPIPE
    at errnoException (net.js:901:11)
    at Object.afterWrite (net.js:718:19)

Change SIGINT to SIGTERM, use a timeout or anything else to trigger the shutdown and it works fine. Maybe SIGINT closes stdin/stdout?

Interestingly it also works if I do process.emit('SIGINT').

I am using Linux (bash).

Thanks.

SystemParadox commented 9 years ago

After further investigation it appears that this is caused by the shell sending the SIGINT to the whole process group, which means both node and phantomJS. So phridge tries to tell phantomJS to exit and gets an EPIPE error (from child.stdin) because it's already gone.

Using kill -SIGINT to send the SIGINT directly to node works as expected.

To fix this I would suggest that phridge needs to catch EPIPE errors and mark that child as destroyed.

Maybe the epipebomb module will come in useful here.

jhnns commented 8 years ago

Should be no problem now