]> Cypherpunks repositories - gostls13.git/commit
runtime: explicitly remove fd's from epoll waitset before close()
authorDmitriy Vyukov <dvyukov@google.com>
Thu, 21 Mar 2013 08:54:19 +0000 (12:54 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Thu, 21 Mar 2013 08:54:19 +0000 (12:54 +0400)
commit44840786ae2a7a24d81df176494e0af5ba9764c4
tree8e2f1c94883410fae135d037db114be98a0aa8f7
parentd4c80d19a80cbdf946102f3b787ce23bf95e4e12
runtime: explicitly remove fd's from epoll waitset before close()
Fixes #5061.

Current code relies on the fact that fd's are automatically removed from epoll set when closed. However, it is not true. Underlying file description is removed from epoll set only when *all* fd's referring to it are closed.

There are 2 bad consequences:
1. Kernel delivers notifications on already closed fd's.
2. The following sequence of events leads to error:
   - add fd1 to epoll
   - dup fd1 = fd2
   - close fd1 (not removed from epoll since we've dup'ed the fd)
   - dup fd2 = fd1 (get the same fd as fd1)
   - add fd1 to epoll = EEXIST

So, if fd can be potentially dup'ed of fork'ed, it's necessary to explicitly remove the fd from epoll set.

R=golang-dev, bradfitz, dave
CC=golang-dev
https://golang.org/cl/7870043
src/pkg/net/fd_unix.go
src/pkg/runtime/netpoll.goc
src/pkg/runtime/netpoll_epoll.c
src/pkg/runtime/netpoll_kqueue.c
src/pkg/runtime/runtime.h