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: Race condition reading IPv4 packets using multiple goroutines #7341

Closed
gopherbot opened this issue Feb 16, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@gopherbot
Copy link

commented Feb 16, 2014

by jleimon:

Two goroutines each create a connection using net.Dial and periodically send ICMP Ping
request packets to two unique host IP addresses. Sometimes a goroutine will read an ICMP
Ping response initiated by the other goroutine. The attached example demonstrates the
behavior.


1. In the attached file 'bug.go', set the variables 'host0' and 'host1' to two unique IP
addresses that are up and that will respond to ICMP Ping request packets.
2. Build the program.
3. Run the program as root. (Max OS X, OpenBSD)
4. The program will send ping packets to the two hosts specified. When a ICMP Ping
response packet is received by a goroutine that did not initiate the request, a 'X' will
be displayed to standard output.

What is the expected output?

The expected output is a never ending stream of dots and no 'X's. (See below)

> sudo ./gonetworkbug 
Password:
Pinging 192.168.1.4...
Pinging 192.168.1.8...
................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

What do you see instead?

> sudo ./gonetworkbug 
Password:
Pinging 192.168.1.4...
Pinging 192.168.1.8...
............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................X....

Which compiler are you using (5g, 6g, 8g, gccgo)?

6g

Which operating system are you using?

Darwin Kernel Version 10.8.0

Which version are you using?  (run 'go version')

go version go1.2 darwin/amd64

Please provide any additional information below.

Bug also present on OpenBSD 5.1

Attachments:

  1. bug.go (2117 bytes)
@mikioh

This comment has been minimized.

Copy link
Contributor

commented Feb 17, 2014

Comment 1:

That's the nature of socket and/or raw IP stuff. net.Dial doesn't specify the near end
identifier and such configuration installs a tuple like [protocol: ICMP for IPv4, src:
<wildcard IP address>, dst: <specified IP address>] into the protocol stack
inside the kernel. If you want to have a socket that works as not only an endpoint on
top of the ICMP for IPv4 but kinda filter, you need to use either net.Dialer or
net.DialIP.
For example, 
var laddr net.Addr
var err error
switch host {
case "192.168.1.4":
        laddr, err = net.ResolveAddr("ip4", "a specified address #1 on your node under the test to prevent a crosstalk using wildcard")
case "192.168.1.8":
        laddr, err = net.ResolveAddr("ip4", "a specified address #2 on your node under the test to prevent a crosstalk using wildcard")
}
if err != nil {
        // error handling
}
d := &net.Dialer{LocalAddr: laddr}
c, err := d.Dial("ip4:icmp", host)

Status changed to Retracted.

@gopherbot gopherbot added the retracted label Feb 17, 2014

@golang golang locked and limited conversation to collaborators Jun 25, 2016

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.