title: Force close all connections in a node.js http server
body: <p>I have an http server created using:</p>
  
  <p><code>var server = http.createServer()</code></p>
  
  <p>I want to shut down the server. Presumably I'd do this by calling:</p>
  
  <p><code>server.close()</code></p>
  
  <p>However, this only prevents the server from receiving any new http connections. It does not close any that are still open. <code>http.close()</code> takes a callback, and that callback does not get executed until all open connections have actually disconnected. Is there a way to force close everything?</p>
  
  <p>The root of the problem for me is that I have Mocha tests that start up an http server in their setup (<code>beforeEach()</code>) and then shut it down in their teardown (<code>afterEach()</code>). But since just calling <code>server.close()</code> won't fully shut things down, the subsequent <code>http.createServer()</code> often results in an <code>EADDRINUSE</code> error. Waiting for <code>close()</code> to finish also isn't an option, since open connections might take a really long time to time out.</p>
  
  <p>I need some way to force-close connections. I'm able to do this client-side, but forcing all of my test connections to close, but I'd rather do it server-side, i.e. to just tell the http server to hard-close all sockets. </p>