2

Possible Duplicate:
Graceful shutdown of a node.JS HTTP server

I have a basic server in Node.js using the http module. While I know a SIGINT event will close the program and stop the server, it seems cleaner to use server.close([callback]) to close the server (I'm doing this on SIGINT event, similar to here). This works nicely as long as the server has not received any requests. As soon as the server gets a request, even if my response is as simple as:

res.writeHead(500, { "Content-Type": "text/plain" });
res.end();

The callback from server.close() never gets called, and closer inspection reveals that server.connections is 1, not 0. (If I have it serve an HTML page with three external scripts, for example, server.connections will be 4.)

Why aren't these connections being terminated by res.end()? What can I do to gracefully stop my server? Or is this just overkill for an imagined problem?

Community
  • 1
  • 1
JacobEvelyn
  • 3,901
  • 1
  • 40
  • 51

0 Answers0