Re: net: remove race condition on Close.

1 view
Skip to first unread message

a...@golang.org

unread,
Nov 17, 2009, 2:27:09 PM11/17/09
to r...@golang.org, golan...@googlegroups.com
We chatted about also fixing the races in Read and Write. I've started
looking at that, but I think that it's a different patch. One needs to
add SHUT_* to syscall, edit os.File to expose it etc.

So I think this patch is self contained and should probably land with
its current scope. I'll do a follow up to fix the other race.

http://codereview.appspot.com/152130

r...@golang.org

unread,
Nov 18, 2009, 2:02:48 AM11/18/09
to a...@golang.org, golan...@googlegroups.com
LGTM



http://codereview.appspot.com/152130/diff/1001/1002
File src/pkg/net/fd.go (right):

http://codereview.appspot.com/152130/diff/1001/1002#newcode121
src/pkg/net/fd.go:121: // Thus fd.fd mirrors the kernel's view of the
file descriptor.
add

// TODO(rsc,agl): There is still a race in Read and Write,
// because they optimistically try to use the fd and don't
// call into the PollServer unless they get EAGAIN.

http://codereview.appspot.com/152130

a...@golang.org

unread,
Nov 18, 2009, 4:18:35 PM11/18/09
to r...@golang.org, golan...@googlegroups.com
*** Submitted as
http://code.google.com/p/go/source/detail?r=ca5c1a5682f8 ***

net: remove race condition on Close.

Previously a netFd could be queued for reading/writing in the channel,
but close(2)'ed before pollServer got to it. In this case, the kernel
would consider the descriptor closed and the attempt to add it to the
epoll set would fail and panic.

This patch makes Close a roundtrip to the pollServer, although the
actual close(2) still occurs elsewhere to avoid blocking the
pollServer.

Fixes issue 143.

R=rsc
CC=golang-dev
http://codereview.appspot.com/152130

Committer: Adam Langley <a...@golang.org>


http://codereview.appspot.com/152130
Reply all
Reply to author
Forward
0 new messages