Skip to content

Commit 09ba8c3

Browse files
authored
DnsNameResolver: Limit connect timeout to query timeout (#13778)
Motivation: We should not use the default connect timeout (10s) but better use the query timeout as the limit Modifications: Use query timeout as connect timeout if any is configured Result: Faster failing connect timeouts when using TCP fallback
1 parent 3370c4e commit 09ba8c3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

resolver-dns/src/main/java/io/netty/resolver/dns/DnsNameResolver.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,11 @@ public DnsNameResolver(
466466
.channelFactory(socketChannelFactory)
467467
.attr(DNS_PIPELINE_ATTRIBUTE, Boolean.TRUE)
468468
.handler(TCP_ENCODER);
469+
if (queryTimeoutMillis > 0 && queryTimeoutMillis <= Integer.MAX_VALUE) {
470+
// Set the connect timeout to the same as queryTimeout as otherwise it might take a long
471+
// time for the query to fail in case of a connection timeout.
472+
socketBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, (int) queryTimeoutMillis);
473+
}
469474
}
470475
switch (this.resolvedAddressTypes) {
471476
case IPV4_ONLY:

0 commit comments

Comments
 (0)