dhcp4: avoid reusing bs between the writing and reading tests.

Although it looks like the sequencing of writing bs to the socket
and reusing the slice for the read test is guaranteed by there being
a receive from the socket in between, the race detector disagrees, and
found a race.
This commit is contained in:
David Anderson 2017-06-01 20:07:28 -07:00
parent 565eb761d1
commit e9e2bb6f2d

View File

@ -70,13 +70,13 @@ func testConn(t *testing.T, impl conn, addr string) {
// Test writing
p.ClientAddr = net.IPv4(127, 0, 0, 1)
dhcpClientPort = s.LocalAddr().(*net.UDPAddr).Port
bs, err = p.Marshal()
bs2, err := p.Marshal()
if err != nil {
t.Fatalf("marshaling packet: %s", err)
}
// Unmarshal the packet again, to smooth out representation
// differences (e.g. nil IP vs. IP set to 0.0.0.0).
p, err = Unmarshal(bs)
p, err = Unmarshal(bs2)
if err != nil {
t.Fatal(err)
}