Remind me, please, about "taking over" a socket

88 views
Skip to first unread message

David Collier-Brown

unread,
May 31, 2019, 12:40:55 AM5/31/19
to golang-nuts
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 (:-()

--dave

Skip Tavakkolian

unread,
May 31, 2019, 1:01:28 AM5/31/19
to David Collier-Brown, golang-nuts
Do you mean like tcp half-close?

--
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 golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/36fabc29-6ccc-45f6-99bb-f728710c6e18%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bakul Shah

unread,
May 31, 2019, 3:11:21 AM5/31/19
to David Collier-Brown, golang-nuts
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.

Bakul Shah

unread,
May 31, 2019, 3:13:12 AM5/31/19
to David Collier-Brown, golang-nuts
On Thu, 30 May 2019 20:10:30 -0700 Bakul Shah <ba...@bitblocks.com> wrote:
>
> 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")

This should've been edited out since we are talking about Listen.
Reply all
Reply to author
Forward
0 new messages