3 ms·
What is the technique to shutdown and restart a server without losing connections? Is it just making sure the connection isn't closed or reset before shutting
by stevewepay 11y ago
What is the technique to shutdown and restart a server without losing connections? Is it just making sure the connection isn't closed or reset before shutting down the server?
- GauntletWizard 11y agoYou don't just need to preserve the socket; You also need to keep both the new and old server in memory for sufficient time that the existing connections die. Perhaps there's a kernel-level API that could be added to allow sockets to be snatched or handed over to a new process. That is, honestly, probably the more apropos solution. The fact that sockets act as a kind of lock is an implementation detail.
- AYBABTME 11y agoThen the new born server would have to know what half-done work has been done/exchanged with the client and recover from there. This seems like an impossible challenge to me, or at least much more complex than sharing the socket while the old server finishes serving its ongoing connections while accepting no new ones.
- GauntletWizard 11y agoI think you've misunderstood me; You don't need/want to share any connections that the old process has, only the listen socket. You 'steal' the socket, and then any 'accept' calls on the previous owners FD behave as if there were no calls, while new connections show up on the thief's socket FD.
- AYBABTME 11y agoI think that's how it's currently done, but the procedure is issued by the dying server. But yes, maybe that'd be cleaner if it was a proper API call initiated by the new born process.
- svieira 11y agoA couple of different ways that I have heard of: * SO_REUSEPORT - not reusing the socket, but allowing multiple sockets to bind to a single port. [1] * Fork / Exec - have a parent process signal the child process to terminate after it has spun up a new version and the new version is accepting connections [2] [1]: https://lwn.net/Articles/542629/ [2]: https://news.ycombinator.com/item?id=9694339