I didn’t know about SO_REUSEPORT, which is pretty cool. I found this article on lwn about it: https://lwn.net/Articles/542629/
It’s a shame that it’s apparently not a good tool to allow new servers to spin up and take over incoming connections without losing any. What is the right way to do such a thing? Do the BSDs (where the idea originated) have a better way of doing this?
See SO_REUSEPORT_LB for FreeBSD
You can pass the existing listening fd over a Unix socket to the new server, or just preserve the fd when you fork and exec by telling the newly exec’d process what the existing listening fd number is.
I’m only familiar with the second approach from back when I dabbled with MUD servers (the server would fork(), then the parent would exec() the new version, and read its state back from the child through a pipe). Are you saying that you can pass file descriptors between arbitrary processes? I thought fds only made sense to a process (including through an exec()) and its children.
Happily you can! CloudFlare wrote a blog post talking about it.
Great writeup! Could probably use the networking tag.