fix(dns): preserve the queried address in UDP replies (#7988)

Bind the embedded DNS listener to the advertised address so connected resolvers accept replies on multi-interface hosts. Preserve the current network-selection behavior.

Ensure the test-owned Vert.x instance is closed even if closing its DNS socket fails. Preserve all UDP source assertions.

Extract a package-private query helper accepting name, type and transaction ID and use it in the reply-source regression. Preserve production DNS behavior and all existing assertions.

Signed-off-by: Andre Kurait <akurait@amazon.com>
This commit is contained in:
Andre Kurait authored and GitHub committed 2026-11-11 10:37:56 -04:00
1 parent 11dafb441c
commit e5a35d6e62
5 files changed
+112 -20

No files matched your search

@@ -180,18 +180,11 @@ public class EmbeddedDnsServer {
}
}
DatagramSocket socket = vertx.createDatagramSocket(new DatagramSocketOptions().setIpV6(false));
socket.listen(DNS_PORT, "0.0.0.0", ar -> {
if (ar.succeeded()) {
serverIp = myIp;
LOG.infov("Embedded DNS server started on {0}:53, resolving {1} → {0}", myIp, suffixes);
socket.handler(packet -> handleQuery(
vertx, socket, packet.data().getBytes(),
packet.sender().host(), packet.sender().port(), myIp));
} else {
LOG.warnv("Embedded DNS server failed to bind on port 53: {0}", ar.cause().getMessage());
}
});
listen(vertx, myIp, DNS_PORT)
.onSuccess(socket -> LOG.infov(
"Embedded DNS server started on {0}:53, resolving {1} → {0}", myIp, suffixes))
.onFailure(error -> LOG.warnv(
"Embedded DNS server failed to bind on {0}:53: {1}", myIp, error.getMessage()));
} catch (Exception e) {
LOG.warnv("Failed to initialize embedded DNS server: {0}", e.getMessage());
}
@@ -201,6 +194,17 @@ public class EmbeddedDnsServer {
return Optional.ofNullable(serverIp);
}
Future<DatagramSocket> listen(Vertx vertx, String address, int port) {
DatagramSocket socket = vertx.createDatagramSocket(new DatagramSocketOptions().setIpV6(false));
// A wildcard bind can reply from a different interface, which DNS clients reject.
return socket.listen(port, address).map(bound -> {
bound.handler(packet -> handleQuery(vertx, bound, packet.data().getBytes(),
packet.sender().host(), packet.sender().port(), address));
serverIp = address;
return bound;
});
}
// ── packet handling ───────────────────────────────────────────────────────
void handleQuery(Vertx vertx, DatagramSocket socket, byte[] data,