Skip to content

p2p: fix flaky test TestServerPortMapping #2108

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

Merged
merged 1 commit into from
Aug 1, 2024
Merged

p2p: fix flaky test TestServerPortMapping #2108

merged 1 commit into from
Aug 1, 2024

Conversation

ucwong
Copy link
Member

@ucwong ucwong commented Aug 1, 2024

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.

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.

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 #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.
@ucwong ucwong merged commit 75f988b into master Aug 1, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants