3 ms·
For web serving (or TCP servers with short-lived connections) in particular, you could do an application-specific smooth transition. But this wouldn't be the r
by loeg 7y ago
For web serving (or TCP servers with short-lived connections) in particular, you could do an application-specific smooth transition. But this wouldn't be the responsibility of TFA's library.
You could have your program use SO_REUSEPORT (or SO_REUSEPORT_LB?) on the socket it listens on. When upgrading, the old version launches the new version, which begins accepting new requests on the configured addresses and ports. The old version closes its listening socket so all new connections are handled by the new version. The old version can then just wait for all existing clients to disconnect, or if the server handles long-poll style loads, maybe send a redirect of some kind to force the client to connect to the new instance. When clients are all exited or some acceptable timeout has expired, the old version can delete itself and exit.