Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/internal/socktest: Data race in net/internal/socktest/switch.go #10796

Closed
pmarks-net opened this issue May 13, 2015 · 2 comments
Closed

net/internal/socktest: Data race in net/internal/socktest/switch.go #10796

pmarks-net opened this issue May 13, 2015 · 2 comments
Labels
FrozenDueToAge Testing
Milestone

Comments

@pmarks-net
Copy link
Contributor

@pmarks-net pmarks-net commented May 13, 2015

When I add the following to net/dial_test.go:

func TestRace(t *testing.T) {
  done := make(chan bool, 2)
  f := func() {
    Dial("tcp", "127.0.0.1:9")
    done <- true
  }
  go f()
  go f()
  <-done
  <-done
}

This race is detected:

$ ../bin/go test net -race -run=TestRace            
==================
WARNING: DATA RACE
Read by goroutine 7:
  net/internal/socktest.(*Switch).Socket()
      /home/pmarks/src/go/src/net/internal/socktest/sys_unix.go:15 +0x15f
  net/internal/socktest.(*Switch).Socket-fm()
      /home/pmarks/src/go/src/net/main_unix_test.go:23 +0x60
  net.sysSocket()
      /home/pmarks/src/go/src/net/sock_cloexec.go:20 +0x94
  net.socket()
      /home/pmarks/src/go/src/net/sock_posix.go:38 +0x71
  net.internetSocket()
      /home/pmarks/src/go/src/net/ipsock_posix.go:137 +0x159
  net.dialTCP()
      /home/pmarks/src/go/src/net/tcpsock_posix.go:176 +0x131
  net.dialSingle()
      /home/pmarks/src/go/src/net/dial.go:243 +0x453
  net.(*Dialer).Dial.func2()
      /home/pmarks/src/go/src/net/dial.go:177 +0x1a6
  net.dial()
      /home/pmarks/src/go/src/net/fd_unix.go:41 +0x7c
  net.(*Dialer).Dial()
      /home/pmarks/src/go/src/net/dial.go:180 +0x71b
  net.Dial()
      /home/pmarks/src/go/src/net/dial.go:147 +0xcf
  net.TestRace.func1()
      /home/pmarks/src/go/src/net/dial_test.go:254 +0x5e

Previous write by goroutine 8:
  net/internal/socktest.(*Switch).addLocked.func1()
      /home/pmarks/src/go/src/net/internal/socktest/switch_unix.go:25 +0x78
  sync.(*Once).Do()
      /home/pmarks/src/go/src/sync/once.go:44 +0xf9
  net/internal/socktest.(*Switch).addLocked()
      /home/pmarks/src/go/src/net/internal/socktest/switch_unix.go:25 +0x7e
  net/internal/socktest.(*Switch).Socket()
      /home/pmarks/src/go/src/net/internal/socktest/sys_unix.go:36 +0x6dd
  net/internal/socktest.(*Switch).Socket-fm()
      /home/pmarks/src/go/src/net/main_unix_test.go:23 +0x60
  net.sysSocket()
      /home/pmarks/src/go/src/net/sock_cloexec.go:20 +0x94
  net.socket()
      /home/pmarks/src/go/src/net/sock_posix.go:38 +0x71
  net.internetSocket()
      /home/pmarks/src/go/src/net/ipsock_posix.go:137 +0x159
  net.dialTCP()
      /home/pmarks/src/go/src/net/tcpsock_posix.go:176 +0x131
  net.dialSingle()
      /home/pmarks/src/go/src/net/dial.go:243 +0x453
  net.(*Dialer).Dial.func2()
      /home/pmarks/src/go/src/net/dial.go:177 +0x1a6
  net.dial()
      /home/pmarks/src/go/src/net/fd_unix.go:41 +0x7c
  net.(*Dialer).Dial()
      /home/pmarks/src/go/src/net/dial.go:180 +0x71b
  net.Dial()
      /home/pmarks/src/go/src/net/dial.go:147 +0xcf
  net.TestRace.func1()
      /home/pmarks/src/go/src/net/dial_test.go:254 +0x5e

Goroutine 7 (running) created at:
  net.TestRace()
      /home/pmarks/src/go/src/net/dial_test.go:257 +0xcd
  testing.tRunner()
      /home/pmarks/src/go/src/testing/testing.go:454 +0xfb

Goroutine 8 (running) created at:
  net.TestRace()
      /home/pmarks/src/go/src/net/dial_test.go:258 +0xe3
  testing.tRunner()
      /home/pmarks/src/go/src/testing/testing.go:454 +0xfb
==================
PASS
Socket statistical information:
(inet4, stream|0x80800, default): opened=2, connected=0, listened=0, accepted=0, closed=2, openfailed=0, connectfailed=2, listenfailed=0, acceptfailed=0, closefailed=0

Found 1 data race(s)
FAIL    net     1.040s
@bradfitz bradfitz added this to the Go1.5 milestone May 13, 2015
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented May 13, 2015

/cc @mikioh

@mikioh mikioh changed the title Data race in net/internal/socktest/switch.go net/internal/socktest: Data race in net/internal/socktest/switch.go May 13, 2015
@mikioh mikioh self-assigned this May 13, 2015
@mikioh mikioh added RaceReport Testing labels May 13, 2015
@gopherbot
Copy link

@gopherbot gopherbot commented May 13, 2015

CL https://golang.org/cl/10007 mentions this issue.

@mikioh mikioh closed this as completed in 645e77e May 13, 2015
@mikioh mikioh removed their assignment May 27, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Testing
Projects
None yet
Development

No branches or pull requests

4 participants