aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime/netpoll_kqueue.c
diff options
context:
space:
mode:
authorDmitriy Vyukov <dvyukov@google.com>2013-03-21 12:54:19 +0400
committerDmitriy Vyukov <dvyukov@google.com>2013-03-21 12:54:19 +0400
commit44840786ae2a7a24d81df176494e0af5ba9764c4 (patch)
tree8e2f1c94883410fae135d037db114be98a0aa8f7 /src/pkg/runtime/netpoll_kqueue.c
parentd4c80d19a80cbdf946102f3b787ce23bf95e4e12 (diff)
downloadgo-44840786ae2a7a24d81df176494e0af5ba9764c4.tar.xz
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
Diffstat (limited to 'src/pkg/runtime/netpoll_kqueue.c')
-rw-r--r--src/pkg/runtime/netpoll_kqueue.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/pkg/runtime/netpoll_kqueue.c b/src/pkg/runtime/netpoll_kqueue.c
index 7603260565..ad721e293e 100644
--- a/src/pkg/runtime/netpoll_kqueue.c
+++ b/src/pkg/runtime/netpoll_kqueue.c
@@ -57,6 +57,15 @@ runtime·netpollopen(int32 fd, PollDesc *pd)
return 0;
}
+int32
+runtime·netpollclose(int32 fd)
+{
+ // Don't need to unregister because calling close()
+ // on fd will remove any kevents that reference the descriptor.
+ USED(fd);
+ return 0;
+}
+
// Polls for ready network connections.
// Returns list of goroutines that become runnable.
G*