Skip to content

Commit

Permalink
When DNS by UDP timeout then fallback to TCP
Browse files Browse the repository at this point in the history
  • Loading branch information
graysonzeng committed Nov 12, 2024
1 parent 137df29 commit e0bd553
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ public ConnectionPool(InstrumentProvider instrumentProvider,
private static AddressResolver<InetSocketAddress> createAddressResolver(ClientConfigurationData conf,
EventLoopGroup eventLoopGroup) {
DnsNameResolverBuilder dnsNameResolverBuilder = new DnsNameResolverBuilder()
.traceEnabled(true).channelType(EventLoopUtil.getDatagramChannelClass(eventLoopGroup));
.traceEnabled(true)
.channelType(EventLoopUtil.getDatagramChannelClass(eventLoopGroup))
.socketChannelType(EventLoopUtil.getSocketChannelClass(eventLoopGroup), true);
if (conf.getDnsLookupBindAddress() != null) {
InetSocketAddress addr = new InetSocketAddress(conf.getDnsLookupBindAddress(),
conf.getDnsLookupBindPort());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ public static Class<? extends ServerSocketChannel> getServerSocketChannelClass(E
}
}

public static Class<? extends SocketChannel> getSocketChannelClass(EventLoopGroup eventLoopGroup) {
if (eventLoopGroup instanceof IOUringEventLoopGroup) {
return IOUringSocketChannel.class;
} else if (eventLoopGroup instanceof EpollEventLoopGroup) {
return EpollSocketChannel.class;
} else {
return NioSocketChannel.class;
}
}

public static Class<? extends DatagramChannel> getDatagramChannelClass(EventLoopGroup eventLoopGroup) {
if (eventLoopGroup instanceof IOUringEventLoopGroup) {
return IOUringDatagramChannel.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ public ProxyService(ProxyConfiguration proxyConfig,
this.authenticationService = authenticationService;

DnsNameResolverBuilder dnsNameResolverBuilder = new DnsNameResolverBuilder()
.channelType(EventLoopUtil.getDatagramChannelClass(workerGroup));
.channelType(EventLoopUtil.getDatagramChannelClass(workerGroup))
.socketChannelType(EventLoopUtil.getSocketChannelClass(workerGroup), true);
DnsResolverUtil.applyJdkDnsCacheSettings(dnsNameResolverBuilder);

dnsAddressResolverGroup = new DnsAddressResolverGroup(dnsNameResolverBuilder);
Expand Down

0 comments on commit e0bd553

Please sign in to comment.