Skip to content

Commit

Permalink
fix(launcher): sigkill after sigint if not dead
Browse files Browse the repository at this point in the history
In some cases chrome on linux does not die when it receives a sigint
signal. So after a sigint is sent wait 2 more seconds and issue a
sigkill if the process is still running.
  • Loading branch information
lzatorski committed Nov 13, 2013
1 parent 9bd71c8 commit 9653c85
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions lib/launchers/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ var BaseBrowser = function(id, emitter, captureTimeout, retryLimit) {
var capturingUrl;
var exitCallback = function() {};

this.killTimeout = 2000;
this.id = id;
this.state = null;
this._tempDir = path.normalize((env.TMPDIR || env.TMP || env.TEMP || '/tmp') + '/karma-' +
id.toString());
this.exitCallbacks = [];


this.start = function(url) {
Expand Down Expand Up @@ -60,18 +62,31 @@ var BaseBrowser = function(id, emitter, captureTimeout, retryLimit) {

this.kill = function(callback) {
exitCallback = callback || function() {};

log.debug('Killing %s', self.name);

if (self.state !== FINISHED) {
if (self.state === FINISHED) {
process.nextTick(exitCallback);
} else if (self.state === BEING_KILLED) {
this.exitCallbacks.push(exitCallback);
} else {
self.state = BEING_KILLED;
self._process.kill();
} else {
process.nextTick(exitCallback);
this.exitCallbacks.push(exitCallback);
setTimeout(self._onKillTimeout, self.killTimeout);
}
};


this._onKillTimeout = function() {
if (self.state !== BEING_KILLED) {
return;
}

log.warn('%s was not killed in %d ms, sending SIGKILL.', self.name, self.killTimeout);

self._process.kill('SIGKILL');
};

this._onTimeout = function() {
if (self.state !== BEING_CAPTURED) {
return;
Expand Down Expand Up @@ -169,6 +184,10 @@ var BaseBrowser = function(id, emitter, captureTimeout, retryLimit) {
}

self.state = FINISHED;
self.exitCallbacks.forEach(function(exitCallback) {
exitCallback();
});
self.exitCallbacks = [];
self._cleanUpTmp(exitCallback);
};

Expand Down

0 comments on commit 9653c85

Please sign in to comment.