Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

PhantomJS was not killed in 2000 ms, sending SIGKILL #27

Closed
sylvain-hamel opened this issue Feb 17, 2014 · 13 comments · Fixed by #29
Closed

PhantomJS was not killed in 2000 ms, sending SIGKILL #27

sylvain-hamel opened this issue Feb 17, 2014 · 13 comments · Fixed by #29

Comments

@sylvain-hamel
Copy link
Contributor

Hi,

On our machines karma-phantomjs-launcher is not able stop PhantomJS when using singleRun: true.

The output is:

PhantomJS was not killed in 2000 ms, sending SIGKILL

I have to CTRL+C to stop it.

Tested on:

  • Windows 8, x64
  • Windows 7, x86

Thanks

@PierreMardon
Copy link

Also on Windows 8.1, x64

@Empujador
Copy link

i have the same problem windows 8, x64

@vojtajina vojtajina added the bug label Mar 14, 2014
@vojtajina
Copy link
Contributor

This might be related to karma-runner/karma#946

@sylvain-hamel
Copy link
Contributor Author

I found the cause. On Windows karma-phantomjs-launcher launches phantomjs.cmd which in turns calls node with \node_modules\phantomjs\bin\phantomjs. As a result, when karma starts the process, it receives the PID of the batch file instead of the PID of the node process. When comes the time to kill the browser, karma kills the batch process instead of the node process.

If I change karma-phantomjs-launcher\index.js and force the path

this._execCommand(
  '"C:\\Program Files\\nodejs\\node.exe"',
  flags.concat(
'C:\\Users\\redhotsly\\AppData\\Roaming\\npm\\node_modules\\phantomjs\\bin\\phantomjs',
 captureFile)
);

Then is works perfectly.


karma-phantomjs-launcher finds the path to launch using require('phantomjs').path which returns a machine specific and hardcoded path stored in phantomjs\lib\location.js which was created during the phantomjs installation (in install.js).


Now, I need a suggestion for how to fix this. One way is that karma-phantomjs-launcher could parse the require('phantomjs').path value and figure out where bin\phantomjs is but that feels hacky to me. I'll implement this hack in my fork but I won't send a pull request until you guys provide more feedback.

sylvain-hamel added a commit to sylvain-hamel/karma-phantomjs-launcher that referenced this issue Mar 15, 2014
Now returns the node.exe process that runs phantom instead of the phantomjs.cmd process
Closes karma-runner#27
@vojtajina
Copy link
Contributor

Thanks @sylvain-hamel !

Stupid Windows, this should kill all children processes too. Besides, I don't understand how it is possible that it worked in 0.10 and does not work in 0.12.

Anyway, I can't think of any better solution than your hack. Isn't there any way to tell Windows to kill child processes when killing a batch process? I mean, even the node process starts another process (phantom.exe) and that one apparently works fine.

@sylvain-hamel
Copy link
Contributor Author

@vojtajina, It did not work w/ 0.10 either. I'll send a PR for my hack then.

sylvain-hamel added a commit to sylvain-hamel/karma-phantomjs-launcher that referenced this issue Apr 1, 2014
Now returns the node.exe process that runs phantom instead of the phantomjs.cmd process
Closes karma-runner#27
@ghost
Copy link

ghost commented Apr 4, 2014

Isn't there any way to tell Windows to kill child processes when killing a batch process?

I have to do this to solve a similiar problem in my protractor tests. The command I use is:

taskkill /T /F /PID <process id>

/T: Terminates the specified process and any child processes which were started by it.
/F: Specifies to forcefully terminate the process(es).

This often for me throws up an error trying to terminate some of the child processes (possibly because the parent already killed it?), but it does the job. I don't know if there's a better way.

@shovemedia
Copy link

I was having the same problem, except the "fix"
sylvain-hamel@f337d5b
seemed to be the cause rather than the solution. I'm running under git-bash on windows (much to my chagrin).

I changed the platform check to:
var isWin = /^win/.test(process.platform);
if (isWin && process.env.term != "cygwin") {
}

and now everything works fine. Definitely YMMV

@sylvain-hamel
Copy link
Contributor Author

@shovemedia the fix that you are refering to was changed a few days later. See #33. Have you tried this version?

@Ciantic
Copy link

Ciantic commented Jun 23, 2017

I'm encountering this with 1.0.4, I wonder what is the go to solution these days.

@gh0st
Copy link

gh0st commented Mar 2, 2018

I've noticed this only fails when passing the --code-coverage flag.

@priyankabmohite
Copy link

I've noticed this only fails when passing the --code-coverage flag.

We are facing same issue even we are not passing --code-coverage flag

@ghost
Copy link

ghost commented Jan 31, 2019

@priyankabmohite and anyone else still following this. Our solution to this and other phantomjs related issues (including it using a very dated webkit engine) was pretty blunt in the end; we moved to ChromeHeadless and have had zero problems since.

Update: I've just noticed the PhantomJS project is now archived, so jumping ship seems especially prudent.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
8 participants