Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

native DNS resolving using Netty on macOS fails #2400

Closed
aviramha opened this issue Apr 27, 2024 · 1 comment · Fixed by #2401
Closed

native DNS resolving using Netty on macOS fails #2400

aviramha opened this issue Apr 27, 2024 · 1 comment · Fixed by #2401

Comments

@aviramha
Copy link
Member

aviramha commented Apr 27, 2024

In a Java project using Netty to resolve DNS on macOS with native netty resolving it tries to access
dns_configuration_copy
to fetch dns configuration, which retrieves it via system api, hence returning the local DNS.
I think the solution would be to hook that function.

Code example

package org.example;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.dns.DefaultDnsOptEcsRecord;
import io.netty.handler.codec.dns.DnsRecord;
import io.netty.resolver.dns.DnsNameResolverBuilder;
import io.netty.util.internal.SocketUtils;
import io.netty.util.concurrent.Future;
import io.netty.resolver.dns.DnsNameResolver;
import io.netty.resolver.dns.DnsAddressResolverGroup;

import java.net.InetAddress;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class Main {
    public static void main(String[] args)
    {
        System.out.println("Hello, World!");
        EventLoopGroup group = new NioEventLoopGroup(1);
        DnsNameResolver resolver = new DnsNameResolverBuilder(group.next())
                .channelType(NioDatagramChannel.class).build();
        Future<List<InetAddress>> caca = resolver.resolveAll("mongo-mongodb.default.svc.cluster.local");
        for (InetAddress address: caca.syncUninterruptibly().getNow()) {
            System.out.println(address);
        }
        resolver.close();
        group.shutdownGracefully(0, 0, TimeUnit.SECONDS);
    }
}
@aviramha
Copy link
Member Author

Related
rust-lang/libc#3667

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant