Skip to content

Commit 8e2d90d

Browse files
committed
internal/poll: be explicit when using runtime netpoller
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 <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 4cff104 commit 8e2d90d

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

src/internal/poll/fd_unix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type FD struct {
4242
// This can be called multiple times on a single FD.
4343
// The net argument is a network name from the net package (e.g., "tcp"),
4444
// or "file".
45+
// Set pollable to true if fd should be managed by runtime netpoll.
4546
func (fd *FD) Init(net string, pollable bool) error {
4647
// We don't actually care about the various network types.
4748
if net == "file" {

src/internal/poll/fd_windows.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ var logInitFD func(net string, fd *FD, err error)
302302
// This can be called multiple times on a single FD.
303303
// The net argument is a network name from the net package (e.g., "tcp"),
304304
// or "file" or "console" or "dir".
305-
func (fd *FD) Init(net string) (string, error) {
305+
// Set pollable to true if fd should be managed by runtime netpoll.
306+
func (fd *FD) Init(net string, pollable bool) (string, error) {
306307
if initErr != nil {
307308
return "", initErr
308309
}
@@ -323,7 +324,7 @@ func (fd *FD) Init(net string) (string, error) {
323324
}
324325

325326
var err error
326-
if !fd.isFile && !fd.isConsole && !fd.isDir {
327+
if pollable {
327328
// Only call init for a network socket.
328329
// This means that we don't add files to the runtime poller.
329330
// Adding files to the runtime poller can confuse matters

src/net/fd_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func newFD(sysfd syscall.Handle, family, sotype int, net string) (*netFD, error)
5252
}
5353

5454
func (fd *netFD) init() error {
55-
errcall, err := fd.pfd.Init(fd.net)
55+
errcall, err := fd.pfd.Init(fd.net, true)
5656
if errcall != "" {
5757
err = wrapSyscallError(errcall, err)
5858
}

src/os/file_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func newFile(h syscall.Handle, name string, kind string) *File {
5454

5555
// Ignore initialization errors.
5656
// Assume any problems will show up in later I/O.
57-
f.pfd.Init(kind)
57+
f.pfd.Init(kind, false)
5858

5959
return f
6060
}

0 commit comments

Comments
 (0)