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

Issue 6604072: code review 6604072: net: fix connection resets when closed on windows (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 6 months ago by brainman
Modified:
11 years, 5 months ago
Reviewers:
CC:
golang-dev, mikio, bradfitz, rsc
Visibility:
Public.

Description

net: fix connection resets when closed on windows It is common to close network connection while another goroutine is blocked reading on another goroutine. This sequence corresponds to windows calls to WSARecv to start io, followed by GetQueuedCompletionStatus that blocks until io completes, and, finally, closesocket called from another thread. We were expecting that closesocket would unblock GetQueuedCompletionStatus, and it does, but not always (http://code.google.com/p/go/issues/detail?id=4170#c5). Also that sequence results in connection is being reset. This CL inserts CancelIo between GetQueuedCompletionStatus and closesocket, and waits for both WSARecv and GetQueuedCompletionStatus to complete before proceeding to closesocket. This seems to fix both connection resets and issue 4170. It also makes windows code behave similar to unix version. Unfortunately, CancelIo needs to be called on the same thread as WSARecv. So we have to employ strategy we use for connections with deadlines to every connection now. It means, there are 2 unavoidable thread switches for every io. Some newer versions of windows have new CancelIoEx api that doesn't have these drawbacks, and this CL uses this capability when available. As time goes by, we should have less of CancelIo and more of CancelIoEx systems. Computers with CancelIoEx are also not affected by issue 4195 anymore. Fixes issue 3710 Fixes issue 3746 Fixes issue 4170 Partial fix for issue 4195

Patch Set 1 #

Patch Set 2 : diff -r 8f3e3876b690 https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 8f3e3876b690 https://go.googlecode.com/hg/ #

Total comments: 8

Patch Set 4 : diff -r 4f26c5344754 https://go.googlecode.com/hg/ #

Total comments: 8

Patch Set 5 : diff -r 4f26c5344754 https://go.googlecode.com/hg/ #

Patch Set 6 : diff -r e489928c34ef https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+265 lines, -76 lines) Patch
M src/pkg/net/fd_unix.go View 1 2 3 4 5 1 chunk +2 lines, -0 lines 0 comments Download
M src/pkg/net/fd_windows.go View 1 2 3 4 17 chunks +90 lines, -74 lines 0 comments Download
M src/pkg/net/net_test.go View 1 1 chunk +39 lines, -0 lines 0 comments Download
M src/pkg/net/rpc/server_test.go View 1 1 chunk +21 lines, -0 lines 0 comments Download
M src/pkg/net/sendfile_windows.go View 1 1 chunk +2 lines, -2 lines 0 comments Download
M src/pkg/net/timeout_test.go View 1 2 3 4 5 1 chunk +79 lines, -0 lines 0 comments Download
M src/pkg/syscall/syscall_windows.go View 1 2 chunks +5 lines, -0 lines 0 comments Download
M src/pkg/syscall/zsyscall_windows_386.go View 1 2 chunks +13 lines, -0 lines 0 comments Download
M src/pkg/syscall/zsyscall_windows_amd64.go View 1 2 chunks +13 lines, -0 lines 0 comments Download
M src/pkg/syscall/ztypes_windows.go View 1 1 chunk +1 line, -0 lines 0 comments Download

Messages

Total messages: 13
brainman
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://go.googlecode.com/hg/
11 years, 6 months ago (2012-10-11 06:28:09 UTC) #1
mikio
It might be better syscall for windows stuff in another CL, perhaps. https://codereview.appspot.com/6604072/diff/5001/src/pkg/net/fd_unix.go File src/pkg/net/fd_unix.go ...
11 years, 6 months ago (2012-10-13 17:13:50 UTC) #2
brainman
Hello golang-dev@googlegroups.com, mikioh.mikioh@gmail.com (cc: golang-dev@googlegroups.com), Please take another look.
11 years, 6 months ago (2012-10-15 04:28:09 UTC) #3
brainman
https://codereview.appspot.com/6604072/diff/5001/src/pkg/net/fd_unix.go File src/pkg/net/fd_unix.go (right): https://codereview.appspot.com/6604072/diff/5001/src/pkg/net/fd_unix.go#newcode674 src/pkg/net/fd_unix.go:674: var skipReadWriteDeadlineTest bool // used for testing current package ...
11 years, 6 months ago (2012-10-15 04:29:22 UTC) #4
bradfitz
https://codereview.appspot.com/6604072/diff/11002/src/pkg/net/fd_windows.go File src/pkg/net/fd_windows.go (right): https://codereview.appspot.com/6604072/diff/11002/src/pkg/net/fd_windows.go#newcode137 src/pkg/net/fd_windows.go:137: // It is used on Windows with no CancelIoEx ...
11 years, 6 months ago (2012-10-16 03:46:42 UTC) #5
brainman
Hello golang-dev@googlegroups.com, mikioh.mikioh@gmail.com, bradfitz@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
11 years, 6 months ago (2012-10-16 06:58:00 UTC) #6
brainman
https://codereview.appspot.com/6604072/diff/11002/src/pkg/net/fd_windows.go File src/pkg/net/fd_windows.go (right): https://codereview.appspot.com/6604072/diff/11002/src/pkg/net/fd_windows.go#newcode137 src/pkg/net/fd_windows.go:137: // It is used on Windows with no CancelIoEx ...
11 years, 6 months ago (2012-10-16 06:58:09 UTC) #7
rsc
I'm happy once Mikio is.
11 years, 6 months ago (2012-10-16 17:41:44 UTC) #8
brainman
ping
11 years, 5 months ago (2012-10-25 00:37:49 UTC) #9
bradfitz
Waiting on Mikio's review? On Wed, Oct 24, 2012 at 5:37 PM, <alex.brainman@gmail.com> wrote: > ...
11 years, 5 months ago (2012-10-25 00:46:08 UTC) #10
brainman
On 2012/10/25 00:46:08, bradfitz wrote: > Waiting on Mikio's review? > I am. Alex
11 years, 5 months ago (2012-10-25 00:46:47 UTC) #11
mikio
LGTM sorry for the late response.
11 years, 5 months ago (2012-10-30 06:08:11 UTC) #12
brainman
11 years, 5 months ago (2012-10-30 23:24:43 UTC) #13
*** Submitted as http://code.google.com/p/go/source/detail?r=8087f34d11d6 ***

net: fix connection resets when closed on windows

It is common to close network connection while another goroutine is
blocked reading on another goroutine. This sequence corresponds to
windows calls to WSARecv to start io, followed by GetQueuedCompletionStatus
that blocks until io completes, and, finally, closesocket called from
another thread. We were expecting that closesocket would unblock
GetQueuedCompletionStatus, and it does, but not always
(http://code.google.com/p/go/issues/detail?id=4170#c5). Also that sequence
results in connection is being reset.

This CL inserts CancelIo between GetQueuedCompletionStatus and closesocket,
and waits for both WSARecv and GetQueuedCompletionStatus to complete before
proceeding to closesocket.  This seems to fix both connection resets and
issue 4170. It also makes windows code behave similar to unix version.

Unfortunately, CancelIo needs to be called on the same thread as WSARecv.
So we have to employ strategy we use for connections with deadlines to
every connection now. It means, there are 2 unavoidable thread switches
for every io. Some newer versions of windows have new CancelIoEx api that
doesn't have these drawbacks, and this CL uses this capability when available.
As time goes by, we should have less of CancelIo and more of CancelIoEx
systems. Computers with CancelIoEx are also not affected by issue 4195 anymore.

Fixes issue 3710
Fixes issue 3746
Fixes issue 4170
Partial fix for issue 4195

R=golang-dev, mikioh.mikioh, bradfitz, rsc
CC=golang-dev
http://codereview.appspot.com/6604072
Sign in to reply to this message.

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