]> Cypherpunks repositories - gostls13.git/commitdiff
internal/poll: be explicit when using runtime netpoller
authorAlex Brainman <alex.brainman@gmail.com>
Mon, 25 Sep 2017 08:54:14 +0000 (18:54 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Tue, 26 Sep 2017 04:39:19 +0000 (04:39 +0000)
internal/poll package assumes that only net sockets use runtime
netpoller on windows. We get memory corruption if other file
handles are passed into runtime poller. Make FD.Init receive
and use useNetpoller argument, so FD.Init caller is explicit
about using runtime netpoller.

Fixes #21172

Change-Id: I60e2bfedf9dda9b341eb7a3e5221035db29f5739
Reviewed-on: https://go-review.googlesource.com/65810
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/internal/poll/fd_unix.go
src/internal/poll/fd_windows.go
src/net/fd_windows.go
src/os/file_windows.go

index c40c701f59c69da9b1aef2f656b400b28cb6c10d..d9538e364b3a73817899ea93c4b5bec9b3e2f2bf 100644 (file)
@@ -42,6 +42,7 @@ type FD struct {
 // This can be called multiple times on a single FD.
 // The net argument is a network name from the net package (e.g., "tcp"),
 // or "file".
+// Set pollable to true if fd should be managed by runtime netpoll.
 func (fd *FD) Init(net string, pollable bool) error {
        // We don't actually care about the various network types.
        if net == "file" {
index f416158bbc5d3901a72c225fa3fb86352c29f6a8..b0991a29f237745cda8a498032c1363c6ea13ed4 100644 (file)
@@ -302,7 +302,8 @@ var logInitFD func(net string, fd *FD, err error)
 // This can be called multiple times on a single FD.
 // The net argument is a network name from the net package (e.g., "tcp"),
 // or "file" or "console" or "dir".
-func (fd *FD) Init(net string) (string, error) {
+// Set pollable to true if fd should be managed by runtime netpoll.
+func (fd *FD) Init(net string, pollable bool) (string, error) {
        if initErr != nil {
                return "", initErr
        }
@@ -323,7 +324,7 @@ func (fd *FD) Init(net string) (string, error) {
        }
 
        var err error
-       if !fd.isFile && !fd.isConsole && !fd.isDir {
+       if pollable {
                // Only call init for a network socket.
                // This means that we don't add files to the runtime poller.
                // Adding files to the runtime poller can confuse matters
index c2156b255e5abd0a36c780ba8ccfec18ee79c250..563558dc52e9905702795f4ed6945954ae0727ba 100644 (file)
@@ -52,7 +52,7 @@ func newFD(sysfd syscall.Handle, family, sotype int, net string) (*netFD, error)
 }
 
 func (fd *netFD) init() error {
-       errcall, err := fd.pfd.Init(fd.net)
+       errcall, err := fd.pfd.Init(fd.net, true)
        if errcall != "" {
                err = wrapSyscallError(errcall, err)
        }
index 93b6c135c72281fba505de866902bc83fbaeaf5d..e2be192bcb66974980beab2af603276fa4cf1949 100644 (file)
@@ -54,7 +54,7 @@ func newFile(h syscall.Handle, name string, kind string) *File {
 
        // Ignore initialization errors.
        // Assume any problems will show up in later I/O.
-       f.pfd.Init(kind)
+       f.pfd.Init(kind, false)
 
        return f
 }