Skip to content

internal/poll: data race in (*FD).SetBlocking #24481

Closed
@twmb

Description

@twmb

What version of Go are you using (go version)?

go version devel +7974f0815e Mon Mar 19 21:51:23 2018 +0000 linux/amd64

This is new in 1.10.

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/twmb/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/twmb/go"
GORACE=""
GOROOT="/home/twmb/go/go"
GOTMPDIR=""
GOTOOLDIR="/home/twmb/go/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build478075614=/tmp/go-build -gno-record-gcc-switches"

What did you do?

For net:
https://play.golang.org/p/p2p0vliZwJB
For os:
https://play.golang.org/p/st7Npi4-2oQ

What did you expect to see?

With go run -race on that file, no leak.

What did you see instead?

==================
WARNING: DATA RACE
Write at 0x00c42013e7af by goroutine 64:
  internal/poll.(*FD).SetBlocking()
      /home/twmb/go/go/src/internal/poll/fd_unix.go:121 +0x8f
  net.(*netFD).dup()
      /home/twmb/go/go/src/net/fd_unix.go:316 +0x7d
  net.(*conn).File()
      /home/twmb/go/go/src/net/net.go:294 +0x4d
  main.main.func2()
      /home/twmb/testing/junk.go:29 +0x3a

Previous write at 0x00c42013e7af by goroutine 66:
  internal/poll.(*FD).SetBlocking()
      /home/twmb/go/go/src/internal/poll/fd_unix.go:121 +0x8f
  net.(*netFD).dup()
      /home/twmb/go/go/src/net/fd_unix.go:316 +0x7d
  net.(*conn).File()
      /home/twmb/go/go/src/net/net.go:294 +0x4d
  main.main.func3()
      /home/twmb/testing/junk.go:34 +0x3a

Goroutine 64 (running) created at:
  main.main()
      /home/twmb/testing/junk.go:28 +0x13f

Goroutine 66 (running) created at:
  main.main()
      /home/twmb/testing/junk.go:33 +0x161
==================

For os:

starting
==================
WARNING: DATA RACE
Write at 0x00c42009416f by goroutine 10:
  internal/poll.(*FD).SetBlocking()
      /home/twmb/go/go/src/internal/poll/fd_unix.go:121 +0x8f
  os.(*File).Fd()
      /home/twmb/go/go/src/os/file_unix.go:69 +0xce

Previous write at 0x00c42009416f by goroutine 11:
  internal/poll.(*FD).SetBlocking()
      /home/twmb/go/go/src/internal/poll/fd_unix.go:121 +0x8f
  os.(*File).Fd()
      /home/twmb/go/go/src/os/file_unix.go:69 +0xce

Goroutine 10 (running) created at:
  main.main()
      /home/twmb/testing/junk.go:18 +0xa3

Goroutine 11 (finished) created at:
  main.main()
      /home/twmb/testing/junk.go:19 +0xc5
==================
done

0f3ab149ec4 introduced SetBlocking on file descriptors that can be pollable. SetBlocking sets isBlocking in a struct. SetBlocking is not called often, but the call itself is unprotected when it is. Documentation does not suggest that the calls themselves should be protected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions