Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporarily remove Grunt's uncaughtException listeners. #103

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jpommerening
Copy link
Contributor

As I mentioned in #93, Grunt's uncaughtException listeners fire before Karma gets a chance to stop the browsers it started.

The only fix that I can think of is removing Grunt's listners for as long as Karma is running. That way, Karma can gracefully handle a framework raising an error or the user pressing Ctrl-c.

I made a small gist to reproduce the problem: https://gist.github.com/jpommerening/10364033

After running npm install, running Grunt will (probably) produce the following output:

$ grunt
Running "karma:unicorns" (karma) task
INFO [karma]: Karma v0.12.6 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Linux)]: Connected on socket 8mpKEfFNXoO5vMb1GWU6 with id 2679007
PhantomJS 1.9.7 (Linux): Executed 1 of 1 SUCCESS (0.038 secs / 0 secs)

Running "karma:explosions" (karma) task
INFO [karma]: Karma v0.12.6 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Linux)]: Connected on socket uo1f5cVKNpntcOFnGWd8 with id 10877927
PhantomJS 1.9.7 (Linux): Executed 1 of 1 SUCCESS (0.039 secs / 0 secs)
Fatal error: Bam!

To try the same thing with the changes in this PR:

$ npm install grunt-karma@jpommerening/grunt-karma#fix-stray-browsers
...
$ grunt
...

@jpommerening
Copy link
Contributor Author

I added another commit to handle SIGINT / Ctrl-c.

Karma listens for SIGINT and takes care of stopping all the browsers. Grunt, however, does not. So after Karma finished, Grunt will just continue running its task queue.

Since Grunt does not listen for SIGINT one would expect Ctrl-c to exit the process immediately. The best we can do is to add our own SIGINT listener and exit the process after Karma is finished.

@jpommerening jpommerening changed the title Temporarily remove uncaughtException listeners. Temporarily remove Grunt's uncaughtException listeners. Apr 11, 2014
Remove these listeners while Karma is running, so that Karma gets a
chance to stop the browsers it started, in case a framework raises
an error or the user presses Ctrl-C.

fixes karma-runner#93
Karma listens for SIGINT and disconnects all servers if interrupted.
As a side-effect, interrupting the current process causes Karma to stop
but nothing else. Any pending Grunt tasks will still run.

Since Grunt does not listen to SIGINT itself, the expected behaviour
is that the process exits with code 130. We simulate this by listening
for SIGINT and calling process.exit() when Karma finished.
@elicwhite
Copy link

This seems long dead, but we still get problems on our CI machine with browsers hanging around from grunt-karma failures. It would great to see this updated and merged.

@dignifiedquire
Copy link
Member

@jpommerening could you rebase this onto latest master please?

@Krinkle Krinkle removed this from the v1.0 milestone Sep 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants