4 ms·
Can't help with how to implement this, but just to be sure: You should be able to use the same port in multiple instances if you bind those with SO_REUSEPORT. A
by dividuum 4y ago
Can't help with how to implement this, but just to be sure: You should be able to use the same port in multiple instances if you bind those with SO_REUSEPORT. A quick search points to https://github.com/libp2p/go-reuseport https://github.com/libp2p/go-reuseport for an implementation. Now you just need a mechanism to drain the old process.
- joncfoo 4y agoRough psuedocode to do this with the built-in http.Server where startServer(..) would use the reuseport library to create the listener so multiple servers can listen within the same process: func reloadConfig(config) { if newServer, err := startServer(config); err != nil { // gracefully shutdown previous server // no new connections will go to old server oldServer.Shutdown(...) oldServer = newServer } }