]> Cypherpunks repositories - gostls13.git/commitdiff
net: add missing aborted connection handling on accept test
authorMikio Hara <mikioh.mikioh@gmail.com>
Fri, 19 Feb 2016 08:45:22 +0000 (17:45 +0900)
committerMikio Hara <mikioh.mikioh@gmail.com>
Sun, 21 Feb 2016 03:32:36 +0000 (03:32 +0000)
This change adds TestAcceptIgnoreAbortedConnRequest to test accepting
aborted connection requests on all supported platforms except Plan 9.

Change-Id: I5936b04085184ff348539962289b1167ec4ac619
Reviewed-on: https://go-review.googlesource.com/19707
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/net/error_plan9_test.go
src/net/error_posix_test.go
src/net/error_unix_test.go [new file with mode: 0644]
src/net/error_windows_test.go [new file with mode: 0644]
src/net/fd_windows.go
src/net/hook_windows.go
src/net/main_windows_test.go
src/net/net_test.go

index 495ea965343a6c5bc47f9a5936de67226bab53e3..d7c7f1487fb14321e5cf1275aad7ad003155e71b 100644 (file)
@@ -9,6 +9,8 @@ import "syscall"
 var (
        errTimedout       = syscall.ETIMEDOUT
        errOpNotSupported = syscall.EPLAN9
+
+       abortedConnRequestErrors []error
 )
 
 func isPlatformError(err error) bool {
index 981cc837ba414a6bbf1bb286792db7c8efc2b825..b411a378dfc70045e02d001aea4a57e886ce72a9 100644 (file)
@@ -12,16 +12,6 @@ import (
        "testing"
 )
 
-var (
-       errTimedout       = syscall.ETIMEDOUT
-       errOpNotSupported = syscall.EOPNOTSUPP
-)
-
-func isPlatformError(err error) bool {
-       _, ok := err.(syscall.Errno)
-       return ok
-}
-
 func TestSpuriousENOTAVAIL(t *testing.T) {
        for _, tt := range []struct {
                error
diff --git a/src/net/error_unix_test.go b/src/net/error_unix_test.go
new file mode 100644 (file)
index 0000000..db66d0a
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build !plan9,!windows
+
+package net
+
+import "syscall"
+
+var (
+       errTimedout       = syscall.ETIMEDOUT
+       errOpNotSupported = syscall.EOPNOTSUPP
+
+       abortedConnRequestErrors = []error{syscall.ECONNABORTED} // see accept in fd_unix.go
+)
+
+func isPlatformError(err error) bool {
+       _, ok := err.(syscall.Errno)
+       return ok
+}
diff --git a/src/net/error_windows_test.go b/src/net/error_windows_test.go
new file mode 100644 (file)
index 0000000..834a9de
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package net
+
+import "syscall"
+
+var (
+       errTimedout       = syscall.ETIMEDOUT
+       errOpNotSupported = syscall.EOPNOTSUPP
+
+       abortedConnRequestErrors = []error{syscall.ERROR_NETNAME_DELETED, syscall.WSAECONNRESET} // see accept in fd_windows.go
+)
+
+func isPlatformError(err error) bool {
+       _, ok := err.(syscall.Errno)
+       return ok
+}
index fd50d772d60d95846f981e09487b7fd281f04438..abdee9d02c921eeb8f3a0d2dae0ed01a896776ee 100644 (file)
@@ -579,7 +579,7 @@ func (fd *netFD) acceptOne(rawsa []syscall.RawSockaddrAny, o *operation) (*netFD
        o.handle = s
        o.rsan = int32(unsafe.Sizeof(rawsa[0]))
        _, err = rsrv.ExecIO(o, "AcceptEx", func(o *operation) error {
-               return syscall.AcceptEx(o.fd.sysfd, o.handle, (*byte)(unsafe.Pointer(&rawsa[0])), 0, uint32(o.rsan), uint32(o.rsan), &o.qty, &o.o)
+               return acceptFunc(o.fd.sysfd, o.handle, (*byte)(unsafe.Pointer(&rawsa[0])), 0, uint32(o.rsan), uint32(o.rsan), &o.qty, &o.o)
        })
        if err != nil {
                netfd.Close()
index 126b0ebdd10ebcef2d3bb4f0af8f2ad08713c5c9..63ea35ab8c444a60bc1710ad01ddb2c5ce77686b 100644 (file)
@@ -13,9 +13,10 @@ var (
        testHookDialChannel = func() { time.Sleep(time.Millisecond) } // see golang.org/issue/5349
 
        // Placeholders for socket system calls.
-       socketFunc    func(int, int, int) (syscall.Handle, error)                                               = syscall.Socket
-       closeFunc     func(syscall.Handle) error                                                                = syscall.Closesocket
-       connectFunc   func(syscall.Handle, syscall.Sockaddr) error                                              = syscall.Connect
-       connectExFunc func(syscall.Handle, syscall.Sockaddr, *byte, uint32, *uint32, *syscall.Overlapped) error = syscall.ConnectEx
-       listenFunc    func(syscall.Handle, int) error                                                           = syscall.Listen
+       socketFunc    func(int, int, int) (syscall.Handle, error)                                                             = syscall.Socket
+       closeFunc     func(syscall.Handle) error                                                                              = syscall.Closesocket
+       connectFunc   func(syscall.Handle, syscall.Sockaddr) error                                                            = syscall.Connect
+       connectExFunc func(syscall.Handle, syscall.Sockaddr, *byte, uint32, *uint32, *syscall.Overlapped) error               = syscall.ConnectEx
+       listenFunc    func(syscall.Handle, int) error                                                                         = syscall.Listen
+       acceptFunc    func(syscall.Handle, syscall.Handle, *byte, uint32, uint32, uint32, *uint32, *syscall.Overlapped) error = syscall.AcceptEx
 )
index 2d829743ec5beac9a3bebc87a7242ca055992417..b8797174258e5199096fb8f4adfb8a1f27ccbb70 100644 (file)
@@ -11,6 +11,7 @@ var (
        origConnect     = connectFunc
        origConnectEx   = connectExFunc
        origListen      = listenFunc
+       origAccept      = acceptFunc
 )
 
 func installTestHooks() {
@@ -19,6 +20,7 @@ func installTestHooks() {
        connectFunc = sw.Connect
        connectExFunc = sw.ConnectEx
        listenFunc = sw.Listen
+       acceptFunc = sw.AcceptEx
 }
 
 func uninstallTestHooks() {
@@ -27,6 +29,7 @@ func uninstallTestHooks() {
        connectFunc = origConnect
        connectExFunc = origConnectEx
        listenFunc = origListen
+       acceptFunc = origAccept
 }
 
 func forceCloseSockets() {
index cd62b4373ebb1aafc66728432e19d808ba32672c..94392928c2df6083949a4f2d10ba4f85ddf878c1 100644 (file)
@@ -6,6 +6,7 @@ package net
 
 import (
        "io"
+       "net/internal/socktest"
        "os"
        "runtime"
        "testing"
@@ -304,3 +305,58 @@ func TestListenCloseListen(t *testing.T) {
        }
        t.Fatalf("failed to listen/close/listen on same address after %d tries", maxTries)
 }
+
+// See golang.org/issue/6163, golang.org/issue/6987.
+func TestAcceptIgnoreAbortedConnRequest(t *testing.T) {
+       switch runtime.GOOS {
+       case "plan9":
+               t.Skipf("%s does not have full support of socktest", runtime.GOOS)
+       }
+
+       syserr := make(chan error)
+       go func() {
+               defer close(syserr)
+               for _, err := range abortedConnRequestErrors {
+                       syserr <- err
+               }
+       }()
+       sw.Set(socktest.FilterAccept, func(so *socktest.Status) (socktest.AfterFilter, error) {
+               if err, ok := <-syserr; ok {
+                       return nil, err
+               }
+               return nil, nil
+       })
+       defer sw.Set(socktest.FilterAccept, nil)
+
+       operr := make(chan error, 1)
+       handler := func(ls *localServer, ln Listener) {
+               defer close(operr)
+               c, err := ln.Accept()
+               if err != nil {
+                       if perr := parseAcceptError(err); perr != nil {
+                               operr <- perr
+                       }
+                       operr <- err
+                       return
+               }
+               c.Close()
+       }
+       ls, err := newLocalServer("tcp")
+       if err != nil {
+               t.Fatal(err)
+       }
+       defer ls.teardown()
+       if err := ls.buildup(handler); err != nil {
+               t.Fatal(err)
+       }
+
+       c, err := Dial(ls.Listener.Addr().Network(), ls.Listener.Addr().String())
+       if err != nil {
+               t.Fatal(err)
+       }
+       c.Close()
+
+       for err := range operr {
+               t.Error(err)
+       }
+}