facebookgo/grace — pull request #10 by kainosnoema (2014-05-15 05:06:35+00:00)
Title: Set "Connection: close" header for keep-alived requests after listener is closed

Go continues to serve requests for open connections that are using keep-alive, so parent processes can stick around for hours if there's a persistent connection that makes repeated requests, even if a server's `ReadTimeout` is set to an appropriate value.

This seemed to be the cleanest, least intrusive way to force all keep-alived connections to close once the listener has closed. We've tested this with our Go HTTP services and it allows the old parent processes to die almost immediately, whereas before we'd sometimes have 6-12 old parents sitting around holding keep-alived connections.

I haven't figured out a great way to test this yet (tried several things without any luck), but I'm open to suggestions.