GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Do not set SO_REUSEADDR on the UDP socket of TestDnsServer by normanmaurer · Pull Request #18270 · netty/netty

Conversation

@normanmaurer

@normanmaurer normanmaurer commented Nov 4, 2026

Copy link
Copy Markdown
Member

Motivation:

DnsNameResolverTest.testNameServerCache occasionally fails on CI with

failed to resolve coccoc.com ==> expected: not equal but was: <12.34.12.34>

The test starts a second TestDnsServer (dnsServer2) that answers every A
query with 12.34.12.34 next to the shared static dnsServer, and routes only
a random subset of the hostnames to it. coccoc.com was not routed to
dnsServer2, and DnsQueryContext only accepts a response whose question
matches the query, so the query itself must have reached dnsServer2.

TestDnsServer enables SO_REUSEADDR on its UDP acceptor before binding to
127.0.0.1:0. On Linux, UDP sockets that both have SO_REUSEADDR set are not
considered to conflict, so the ephemeral port selection can hand out a port
that is already used by another such socket. When dnsServer2 gets the same
port as dnsServer, the kernel delivers all datagrams for that port to the
newest socket, which then answers queries that were meant for dnsServer
using dnsServer's address as the source. The resolver rightfully accepts
that response.

UDP has no TIME_WAIT state, so nothing in the tests needs the option.

Modification:

Remove the setReuseAddress(true) call from TestDnsServer.start(...). The
only start with a fixed port takes the port from a TCP ServerSocket, so it
does not depend on the option either.

Result:

A TestDnsServer can no longer silently share its port with another one. A
port clash now fails the bind instead of routing queries to the wrong
server, which removes the flakiness of testNameServerCache (and any other
test that starts more than one TestDnsServer).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@normanmaurer
Do not set SO_REUSEADDR on the UDP socket of TestDnsServer
d067dad
Motivation:

DnsNameResolverTest.testNameServerCache occasionally fails on CI with

    failed to resolve coccoc.com ==> expected: not equal but was: <12.34.12.34>

The test starts a second TestDnsServer (dnsServer2) that answers every A
query with 12.34.12.34 next to the shared static dnsServer, and routes only
a random subset of the hostnames to it. coccoc.com was not routed to
dnsServer2, and DnsQueryContext only accepts a response whose question
matches the query, so the query itself must have reached dnsServer2.

TestDnsServer enables SO_REUSEADDR on its UDP acceptor before binding to
127.0.0.1:0. On Linux, UDP sockets that both have SO_REUSEADDR set are not
considered to conflict, so the ephemeral port selection can hand out a port
that is already used by another such socket. When dnsServer2 gets the same
port as dnsServer, the kernel delivers all datagrams for that port to the
newest socket, which then answers queries that were meant for dnsServer
using dnsServer's address as the source. The resolver rightfully accepts
that response.

UDP has no TIME_WAIT state, so nothing in the tests needs the option.

Modification:

Remove the setReuseAddress(true) call from TestDnsServer.start(...). The
only start with a fixed port takes the port from a TCP ServerSocket, so it
does not depend on the option either.

Result:

A TestDnsServer can no longer silently share its port with another one. A
port clash now fails the bind instead of routing queries to the wrong
server, which removes the flakiness of testNameServerCache (and any other
test that starts more than one TestDnsServer).
@normanmaurer normanmaurer added this to the 4.2.21.Final milestone Nov 4, 2026
@normanmaurer normanmaurer added needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Nov 4, 2026
@testlens-app

testlens-app Bot commented Nov 5, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: d067dad
▶️ Tests: 37930 executed
⚪️ Checks: 31/31 completed


Learn more about TestLens at testlens.app/docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer
normanmaurer merged commit d6c25f4 into 4.2 Nov 5, 2026
32 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer
normanmaurer deleted the reuse_test_fix branch November 5, 2026 15:28
@netty-project-bot netty-project-bot mentioned this pull request Nov 5, 2026
Auto-port 4.1: Do not set SO_REUSEADDR on the UDP socket of TestDnsServer #18275
Merged
@netty-project-bot

netty-project-bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Auto-port PR for 4.1: #18275

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. label Nov 5, 2026
@netty-project-bot netty-project-bot mentioned this pull request Nov 5, 2026
Auto-port 5.0: Do not set SO_REUSEADDR on the UDP socket of TestDnsServer #18276
Merged
@netty-project-bot

netty-project-bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Auto-port PR for 5.0: #18276

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Nov 5, 2026
normanmaurer added a commit that referenced this pull request Nov 5, 2026
@netty-project-bot @normanmaurer
Auto-port 4.1: Do not set SO_REUSEADDR on the UDP socket of TestDnsSe…
cdfde10
…rver (#18275)

Auto-port of #18270 to 4.1
Cherry-picked commit: d6c25f4

---
Motivation:

DnsNameResolverTest.testNameServerCache occasionally fails on CI with

failed to resolve coccoc.com ==> expected: not equal but was:
<12.34.12.34>

The test starts a second TestDnsServer (dnsServer2) that answers every A
query with 12.34.12.34 next to the shared static dnsServer, and routes
only
a random subset of the hostnames to it. coccoc.com was not routed to
dnsServer2, and DnsQueryContext only accepts a response whose question
matches the query, so the query itself must have reached dnsServer2.

TestDnsServer enables SO_REUSEADDR on its UDP acceptor before binding to
127.0.0.1:0. On Linux, UDP sockets that both have SO_REUSEADDR set are
not
considered to conflict, so the ephemeral port selection can hand out a
port
that is already used by another such socket. When dnsServer2 gets the
same
port as dnsServer, the kernel delivers all datagrams for that port to
the
newest socket, which then answers queries that were meant for dnsServer
using dnsServer's address as the source. The resolver rightfully accepts
that response.

UDP has no TIME_WAIT state, so nothing in the tests needs the option.

Modification:

Remove the setReuseAddress(true) call from TestDnsServer.start(...). The
only start with a fixed port takes the port from a TCP ServerSocket, so
it
does not depend on the option either.

Result:

A TestDnsServer can no longer silently share its port with another one.
A
port clash now fails the bind instead of routing queries to the wrong
server, which removes the flakiness of testNameServerCache (and any
other
test that starts more than one TestDnsServer).

Co-authored-by: Norman Maurer <[email protected]>
normanmaurer added a commit that referenced this pull request Nov 5, 2026
@netty-project-bot @normanmaurer
Auto-port 5.0: Do not set SO_REUSEADDR on the UDP socket of TestDnsSe…
abb71b5
…rver (#18276)

Auto-port of #18270 to 5.0
Cherry-picked commit: d6c25f4

---
Motivation:

DnsNameResolverTest.testNameServerCache occasionally fails on CI with

failed to resolve coccoc.com ==> expected: not equal but was:
<12.34.12.34>

The test starts a second TestDnsServer (dnsServer2) that answers every A
query with 12.34.12.34 next to the shared static dnsServer, and routes
only
a random subset of the hostnames to it. coccoc.com was not routed to
dnsServer2, and DnsQueryContext only accepts a response whose question
matches the query, so the query itself must have reached dnsServer2.

TestDnsServer enables SO_REUSEADDR on its UDP acceptor before binding to
127.0.0.1:0. On Linux, UDP sockets that both have SO_REUSEADDR set are
not
considered to conflict, so the ephemeral port selection can hand out a
port
that is already used by another such socket. When dnsServer2 gets the
same
port as dnsServer, the kernel delivers all datagrams for that port to
the
newest socket, which then answers queries that were meant for dnsServer
using dnsServer's address as the source. The resolver rightfully accepts
that response.

UDP has no TIME_WAIT state, so nothing in the tests needs the option.

Modification:

Remove the setReuseAddress(true) call from TestDnsServer.start(...). The
only start with a fixed port takes the port from a TCP ServerSocket, so
it
does not depend on the option either.

Result:

A TestDnsServer can no longer silently share its port with another one.
A
port clash now fails the bind instead of routing queries to the wrong
server, which removes the flakiness of testNameServerCache (and any
other
test that starts more than one TestDnsServer).

Co-authored-by: Norman Maurer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.2.21.Final

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@normanmaurer @netty-project-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.