On Thu, 30 May 2019 17:40:55 -0700 David Collier-Brown <[email protected]>
wrote:
>
> My leaky brain has lost an old technique...
>
> Once upon a time, I would send an old copy of a program a SIGHUP, and it
> would shut down a socket listening on, for example, port 25 (SMTP). A newer
> release of the program would succeeding in binding to port 25, taking over
> any new connection requests. When the old program closed it's last email
> transfer, it would then exit.
>
> The idea was to update a (mail-)server implementation without losing
> transactions.
>
> I can no longer find the code I once used, nor other people's examples,
> much less modern Golang examples!
>
> Please tell me we haven't lost this technique (:-()
man setsockopt and look for SO_REUSEADDR/SO_REUSEPORT
You will have to use low level code like Socket(), Bind() etc. You can't
use e.g. Dial("tcp", "192.168.1.1:smtp")
Something like
err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1)
https://github.com/libp2p/go-reuseport has an example.
Though IMHO such ports should be passed from an *external*
program for security purposes (your service enpoint shouldn't
be opening any ports on its own). Also makes it easier to
test.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/20190531031037.892A0156E40C%40mail.bitblocks.com.
For more options, visit https://groups.google.com/d/optout.