Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(7325)

Issue 7870043: code review 7870043: runtime: explicitly remove fd's from epoll waitset befo... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 1 month ago by dvyukov
Modified:
11 years, 1 month ago
Reviewers:
CC:
golang-dev, bradfitz, dfc
Visibility:
Public.

Description

runtime: explicitly remove fd's from epoll waitset before close() Fixes issue 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.

Patch Set 1 #

Patch Set 2 : diff -r b5b5c246be0c https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 3 : diff -r b5b5c246be0c https://dvyukov%40google.com@code.google.com/p/go/ #

Total comments: 3

Patch Set 4 : diff -r e4e13824b6a3 https://dvyukov%40google.com@code.google.com/p/go/ #

Total comments: 1

Patch Set 5 : diff -r 0d7891ca5e06 https://dvyukov%40google.com@code.google.com/p/go/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+29 lines, -2 lines) Patch
M src/pkg/net/fd_unix.go View 1 2 3 4 1 chunk +3 lines, -1 line 0 comments Download
M src/pkg/runtime/netpoll.goc View 1 3 chunks +3 lines, -0 lines 0 comments Download
M src/pkg/runtime/netpoll_epoll.c View 1 1 chunk +13 lines, -1 line 0 comments Download
M src/pkg/runtime/netpoll_kqueue.c View 1 1 chunk +9 lines, -0 lines 0 comments Download
M src/pkg/runtime/runtime.h View 1 1 chunk +1 line, -0 lines 0 comments Download

Messages

Total messages: 10
dvyukov
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://dvyukov%40google.com@code.google.com/p/go/
11 years, 1 month ago (2013-03-16 14:46:12 UTC) #1
bradfitz
https://codereview.appspot.com/7870043/diff/4001/src/pkg/runtime/netpoll_epoll.c File src/pkg/runtime/netpoll_epoll.c (right): https://codereview.appspot.com/7870043/diff/4001/src/pkg/runtime/netpoll_epoll.c#newcode42 src/pkg/runtime/netpoll_epoll.c:42: return -res; this part (returning negative, where you used ...
11 years, 1 month ago (2013-03-16 15:54:38 UTC) #2
dvyukov
https://codereview.appspot.com/7870043/diff/4001/src/pkg/runtime/netpoll_epoll.c File src/pkg/runtime/netpoll_epoll.c (right): https://codereview.appspot.com/7870043/diff/4001/src/pkg/runtime/netpoll_epoll.c#newcode42 src/pkg/runtime/netpoll_epoll.c:42: return -res; On 2013/03/16 15:54:38, bradfitz wrote: > this ...
11 years, 1 month ago (2013-03-16 17:18:37 UTC) #3
dfc
Thank you Dmitry. Could you please add some text to the description explaining why this ...
11 years, 1 month ago (2013-03-16 20:47:38 UTC) #4
dvyukov
On 2013/03/16 20:47:38, dfc wrote: > Thank you Dmitry. Could you please add some text ...
11 years, 1 month ago (2013-03-17 07:49:30 UTC) #5
dfc
Thank you. Given the pd.Close doesn't close anything, is it possible to rename it to ...
11 years, 1 month ago (2013-03-17 09:34:18 UTC) #6
dvyukov
It abstractedly closes poller, the operation can include removing, unregistering or closing something. On Sun, ...
11 years, 1 month ago (2013-03-17 09:53:09 UTC) #7
bradfitz
LGTM https://codereview.appspot.com/7870043/diff/12001/src/pkg/net/fd_unix.go File src/pkg/net/fd_unix.go (right): https://codereview.appspot.com/7870043/diff/12001/src/pkg/net/fd_unix.go#newcode127 src/pkg/net/fd_unix.go:127: // Poller may want to unregister fd in ...
11 years, 1 month ago (2013-03-18 20:56:02 UTC) #8
dvyukov
On 2013/03/18 20:56:02, bradfitz wrote: > LGTM > > https://codereview.appspot.com/7870043/diff/12001/src/pkg/net/fd_unix.go > File src/pkg/net/fd_unix.go (right): > ...
11 years, 1 month ago (2013-03-21 08:54:03 UTC) #9
dvyukov
11 years, 1 month ago (2013-03-21 08:54:25 UTC) #10
*** Submitted as https://code.google.com/p/go/source/detail?r=ff779e477085 ***

runtime: explicitly remove fd's from epoll waitset before close()
Fixes issue 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://codereview.appspot.com/7870043
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b