Skip to content

Commit

Permalink
p2p: fix flaky test TestServerPortMapping (ethereum#30241)
Browse files Browse the repository at this point in the history
The test specifies `ListenAddr: ":0"`, which means a random ephemeral
port will be chosen for the TCP listener by the OS. Additionally, since
no `DiscAddr` was specified, the same port that is chosen automatically
by the OS will also be used for the UDP listener in the discovery UDP
setup. This sometimes leads to test failures if the TCP listener picks a
free TCP port that is already taken for UDP. By specifying `DiscAddr:
":0"`, the UDP port will be chosen independently from the TCP port,
fixing the random failure.

See issue ethereum#29830.

Verified using
```
cd p2p
go test -c -race
stress ./p2p.test -test.run=TestServerPortMapping
...
5m0s: 4556 runs so far, 0 failures
```

The issue described above can technically lead to sporadic failures on
systems that specify a listen address via the `--port` flag of 0 while
not setting `--discovery.port`. Since the default is using port `30303`
and using a random ephemeral port is likely not used much to begin with,
not addressing the root cause might be acceptable.
  • Loading branch information
bearpebble authored Jul 30, 2024
1 parent b0f66e3 commit 6e33dbf
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions p2p/server_nat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestServerPortMapping(t *testing.T) {
PrivateKey: newkey(),
NoDial: true,
ListenAddr: ":0",
DiscAddr: ":0",
NAT: mockNAT,
Logger: testlog.Logger(t, log.LvlTrace),
clock: clock,
Expand Down

0 comments on commit 6e33dbf

Please sign in to comment.