Skip to content

Instantly share code, notes, and snippets.

@fabiosantoscode
Created February 16, 2016 16:22
Show Gist options
  • Save fabiosantoscode/29a7455745653ccd7433 to your computer and use it in GitHub Desktop.
Save fabiosantoscode/29a7455745653ccd7433 to your computer and use it in GitHub Desktop.
/*...*/
try {
} catch(e) {
// OMG AN ERROR, WE HAVE TO CLOSE
// It's a good thing we caught this so we don't crash.
// Now let's call close() which allows us to bail gracefully
server.close(() => {
console.error(e)
process.exit(1)
// Ok we seem to be done.
// But this callback is only called when all the sockets are closed
// And some jackass can still be sending application-level heartbeats so they don't time out for inactivity.
// We need to time out the server closing
})
// Like, 15 seconds
setTimeout(() => { console.error(e); process.exit(1) }, 15 * 1000)
}
/*...*/
@tomgco
Copy link

tomgco commented Feb 16, 2016

This all depends on your application and the types of requests that you are receiving.

If you are pretty much serving up static html files then yes, after 10 seconds drop the connections.
However if you had clients connecting with http long polling and you are handling this somehow as part of your application then maybe this isn't the best solution as some clients might still need to be connected.

Maybe a better way around this jackass would be to stop them at the request level for doing such a thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment