Skip to content

Commit

Permalink
killing phantom harder
Browse files Browse the repository at this point in the history
🐗
  • Loading branch information
jifeon committed Dec 24, 2015
1 parent 9893626 commit a685dbe
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions lib/PhantomEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ PhantomEnvironment.prototype = _.create(Environment.prototype, /**@lends Phantom
},

mouseup: function (selector) {
console.log('mouseup');
return this._getElementPosition(selector)
.then(function (position) {
this._page.sendEvent('mouseup', position.x, position.y);
Expand Down Expand Up @@ -322,8 +321,32 @@ PhantomEnvironment.prototype = _.create(Environment.prototype, /**@lends Phantom
* @private
*/
tearDown: function () {
this._phantomJS.exit(0);
debug('._tearDownInstance() tearing down');
var phantom = this._phantomJS;
if (!this._phantomJS.process) {
debug('Phantom process already exited, not killing');
return;
}

var pid = phantom.process.pid;

debug('Terminating phantom process gracefully, pid: ', pid);
phantom.exit();

setTimeout(function () {
debug('Checking if process is still alive, pid: %s', pid);
if (phantom.process != null) {
debug('Terminating phantom process with SIGTERM, pid: %s', pid);
phantom.process.kill('SIGTERM');
setTimeout(function () {
debug('Checking if process is still alive after SIGTERM, pid: %s', pid);
if (phantom.process != null) {
debug('Terminating phantom process with SIGKILL, pid: %s', pid);
phantom.process.kill('SIGKILL');
}
}, 100);
}
}, 100);
},

/**
Expand Down Expand Up @@ -549,6 +572,7 @@ PhantomEnvironment.prototype = _.create(Environment.prototype, /**@lends Phantom
}, this),
this._on('exit', function (code, signal) {
debug('Phantom exited with code ' + code + ' and signal ' + signal);
delete this._phantomJS.process;
}),
this._on('error', function (msg, trace) {
phantomError('%s, trace %o, file %s errbacks', msg, trace, this._errbacks.length);
Expand Down

0 comments on commit a685dbe

Please sign in to comment.