fix(dns): forward queries without per-context ordering (#4643)

Forwards ran through the one-argument executeBlocking, which is ordered per
Vert.x context. Every forward is submitted from the DNS socket's event-loop
context, so one unresponsive upstream or rule target held up forwarding for
every other query until it timed out. Both forwarding paths now go through
submitForward, which passes ordered=false, the same as planQuery already does.

Unordered forwards could otherwise take every thread of the shared worker pool
during a burst of queries to a dead resolver, starving planQuery and the rest
of the emulator, so they run on a dedicated shared executor capped at 8 threads.

Fixes #4606
This commit is contained in:
Sam Fakhreddine authored and GitHub committed 2026-10-08 18:31:24 -04:00
1 parent aa94969704
commit 89f59dea62
2 files changed
+60 -2

No files matched your search

@@ -1,5 +1,7 @@
package io.github.hectorvent.floci.core.common.dns;
import io.vertx.core.Vertx;
import io.vertx.core.WorkerExecutor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -11,6 +13,8 @@ import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.*;
@@ -673,6 +677,29 @@ class EmbeddedDnsServerTest {
List.of(new DnsForwardingRule.Target("127.0.0.1", 1))));
}
@Test
void submitForward_slowForwardDoesNotBlockTheNextOneOnTheSameContext() throws Exception {
// Catches: forwards submitted from one event-loop context run one at a time, so a single
// unresponsive upstream stalls every other query's forwarding until it times out.
Vertx vertx = Vertx.vertx();
WorkerExecutor pool = vertx.createSharedWorkerExecutor("dns-forward-test", 2);
CountDownLatch releaseSlow = new CountDownLatch(1);
CountDownLatch fastDone = new CountDownLatch(1);
try {
vertx.getOrCreateContext().runOnContext(v -> {
EmbeddedDnsServer.submitForward(pool, () -> releaseSlow.await(10, TimeUnit.SECONDS));
EmbeddedDnsServer.submitForward(pool, () -> {
fastDone.countDown();
return null;
});
});
assertTrue(fastDone.await(5, TimeUnit.SECONDS));
} finally {
releaseSlow.countDown();
vertx.close().toCompletionStage().toCompletableFuture().get(10, TimeUnit.SECONDS);
}
}
/** Replies to the first datagram received with a fixed payload, on a daemon thread. */
private void startResponder(DatagramSocket responder, byte[] responsePayload) {
Thread t = new Thread(() -> {