I don't have anything to add to my earlier note: it's probably fine to
skip the Shutdown and check fd.closing in Read, etc. That might require
using two different closing flags, one for read and one for write, and
having Close use rio.Lock and wio.Lock before setting the appropriate
flags.
Ian
Shutdown was the easiest way to ensure both of those
but it may be possible to do without it. If you can, great!
Russ
I've run into a new issue with Shutdown.
Is Shutdown also necessary on listen sockets?
Closing a listen socket should presumably cause any accepts on that
socket to unblock? Is Shutdown necessary for that?
We've managed to avoid passing client sockets between Go processes,
but Go also calls Shutdown on listen sockets, which causes some
discomfort for systemd, because it didn't expect services to call
shutdown on the sockets it passes in:
http://lists.freedesktop.org/archives/systemd-devel/2011-April/002084.html
Maybe we should just avoid calling Shutdown on listen sockets as a
first step? I can submit a CL if that makes sense.
Regards
Albert
> On Feb 9, 5:28 am, Russ Cox <r...@golang.org> wrote:
>> It's fine to remove Shutdown as long as you manage to
>> (1) keep from closing a file descriptor until there is
>> no chance of any goroutines using it in a system call,
>> (2) make sure that Close causes any blocked reads
>> and writes to wake up and return whatever error it is
>> that they return.
>> Shutdown was the easiest way to ensure both of those
>> but it may be possible to do without it. If you can, great!
>
> Is Shutdown also necessary on listen sockets?
>
> Closing a listen socket should presumably cause any accepts on that
> socket to unblock? Is Shutdown necessary for that?
Go code doesn't block on the accept system call, so the question is
whether closing a socket will cause it to be marked as available for
read. That is Russ's question 2 above. On GNU/Linux using epoll an
EPOLLHUP event should occur, which should indeed cause the goroutine to
wake up, and the call to Accept will most likely fail with an EBADF
error indication.
Ian