I'm trying out a scheme for a daemon which reloads on SIGHUP without
closing the listener - and without forking.
So what I came up with is something like the attached. (it won't run in
The problem is that net.http.Server.Serve(listener) insists on closing
the listener on exit.
So I can't trust that method with the only file descriptor in the
application, but only with a copy.
This works great, but sometimes I need another call to
net.TCPListener.File() (*) - and then it changes behavior.
Try uncomment the first code block....
After the addition the server will no longer exit on SIGINT directly but
hangs until it receives the first connection on the socket.
Accept() doesn't wake up before there's activity - even though the FD is
The reason seems to be that .File() sets the underlying FDs in blocking
Setting the new *os.File.Fd() to non-blocking makes it behave as before.
I can understand from reading up on old issues that I'm not the first to
encounter artifacts from dup() setting blocking mode.
But the comment in http://golang.org/src/net/fd_unix.go line ~500 seems
to indicate that everything should work as if it didn't set blocking.
However - it does not. And there's also some kind og assymetry. For some
reason the first .File() call didn't cause this.
So having an *os.File in the main() function and passing it to a
function which instantiates a listener with net.FileListener() seems to
But having a function create a net.TCPListener and return an *os.File()
copy via TCPListener.File() to the main loop does not.
One would guess that the result should be the same.
Is there some documentation missing for the behavior package net calls
which cause duplication of file descriptors?
PS: Using golang 1.3.3 on Debian Jessie
*: The reason is that it's a part of a larger framework were the outer
code doesn't know what kind of sockets are used. It just needs to get an
*os.File back it can hold onto while reloading
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 firstname.lastname@example.org.
For more options, visit https://groups.google.com/d/optout.