12 ms·
We use SO_REUSEPORT [1] to implement graceful restarts. There's a library for go that allows you to do that [2]. 1. https://lwn.net/Articles/542629/ https://lw
by petethepig 10y ago
We use SO_REUSEPORT [1] to implement graceful restarts. There's a library for go that allows you to do that [2].
1. https://lwn.net/Articles/542629/ https://lwn.net/Articles/542629/
2. https://github.com/kavu/go_reuseport https://github.com/kavu/go_reuseport
- amenghra 10y agoExample of code using SO_REUSEPORT. Ghostunnel does it to reload short lived certificates: https://github.com/square/ghostunnel/blob/master/main.go#L306 https://github.com/square/ghostunnel/blob/master/main.go#L30...
- alpb 10y agoHow does it do that without dropping open connections (does it drain)?
- amenghra 10y agoYou can close the socket without dropping existing connections.
- petethepig 10y agoHere's how it works in our case: 1. Start a new process, start accepting new connections 2. In your old process, stop accepting new connections — old ones are still active. 3. In the old process, close old connections when they become idle. 4. In the old process, wait until all of your connections are closed and then quit or automatically quit after a timeout.