title: Node.js: shutting down Karma server kills parent process
body: <p>I'm involved in an OSS project that provides mutation testing for Javascript - basically testing unit test effectiveness by mutating the code that the unit test tests. </p>
  
  <p>An inevitable effect of mutating code is that you may run into endless loops:</p>
  
  <pre><code>while(var i=0; i&lt;10; i++){...}
  </code></pre>
  
  <p>could become </p>
  
  <pre><code>while(var i=0; i&lt;10; i--){...}
  </code></pre>
  
  <p>While some basic mutations (such as this one) can be excluded it is not possible (nor IMO desirable) to exclude every mutation that could possibly cause an infinite loop.
  Instead I have been focusing on detecting an infinite loop, terminating the current mutation test with a warning and continuing with the next mutation. </p>
  
  <p>In Karma, however I run into a problem: a loop like the above will keep the browser occupied and send your CPU to 100%. When I try to shut down the Karma server I get the following error:</p>
  
  <pre><code>Fatal error: socket hang up
  Process finished with exit code 3
  </code></pre>
  
  <p>This not only kills my parent process, thus leaving all remaining mutations untested, but also leaves child processes (I'm running a small pool of karma server instances) dangling which I then have to kill manually.</p>
  
  <p>I've been struggling with this for quite some time now and it feels like I've hit a concrete wall. Any help is very much appreciated.</p>
  
  <h2>How to reproduce?</h2>
  
  <p>If you want more information/context, feel free to check out the project at <a href="https://github.com/jimivdw/grunt-mutation-testing/tree/kill_looping_karma_servers" rel="nofollow">https://github.com/jimivdw/grunt-mutation-testing/tree/kill_looping_karma_servers</a></p>
  
  <p>In that branch I have a file called <strong>script_endlessLoop.js</strong> which, when mutated, causes an infinite loop on a number of occasions. I have disabled mutations for now by adding @excludeMutations, so that needs to be removed or modified. Then running <code>grunt test:karma</code> should give you the above error. 
  <strong>Please be careful! Make sure you clean up all node related processes after running this as it could cause your computer to slow down severely</strong>  </p>