GlowstoneMC / Glowstone

A fast, customizable and compatible open source server for Minecraft: Java Edition
https://glowstone.net
Other
1.88k stars 271 forks source link

Use cloudflare DNS for session server IP lookup #1010

Closed heisluft closed 5 years ago

heisluft commented 5 years ago

This PR fixes an issue where the client would be kicked with the message: internal error during login. The server complains about not being able to reach the mojang session server, failing with a timeout exception. This is because netty's DefaultDnsServerAddressStreamProvider which uses Googles DNS servers (8.8.8.8 and 8.8.4.4) for IP lookup. This PR changes the DNS servers tou cloudflare's (1.1.1.1) thus resolving the issue.

This has been tested many times (it was frustrating to not be able to play on my server for 2 months now) and is proven to solve my issue (Thanks for your fast support on Discord, that really helped :D)

CLAassistant commented 5 years ago

CLA assistant check
All committers have signed the CLA.

smartboyathome commented 5 years ago

Nice find, but is it possible to use the system's configured DNS server? I don't believe we should be ignoring what is configured in the system. Alternatively, if it's not possible to use the system's configured DNS, we should change these to be configurable rather than hardcoding defaults to a single provider that, for one reason or another, someone may object to.

heisluft commented 5 years ago

Will address that as soon as i got time again (hopefully tomorrow). It seems like DefaultDnsServerAddressStreamProvider first tries to resolve the systems dns servers and uses google as fallback: excerpt from DefaultDnsServerAddressStreamProvider:

 // Using jndi-dns to obtain the default name servers.
        //
        // See:
        // - http://docs.oracle.com/javase/8/docs/technotes/guides/jndi/jndi-dns.html
        // - http://mail.openjdk.java.net/pipermail/net-dev/2017-March/010695.html
        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
        env.put("java.naming.provider.url", "dns://");
        try {
            DirContext ctx = new InitialDirContext(env);
            String dnsUrls = (String) ctx.getEnvironment().get("java.naming.provider.url");
            // Only try if not empty as otherwise we will produce an exception
            if (dnsUrls != null && !dnsUrls.isEmpty()) {
                String[] servers = dnsUrls.split(" ");

But this raises the question why it wouldn't be able to resolve the session servers: curling them gives me back correct results, so it can't be my DNS config (or something is REALLY broken on my end).

mastercoms commented 5 years ago

These defaults do not respect your host's machines defaults.

The docs suggest otherwise.

heisluft commented 5 years ago

Appearantly, I was able to reach the sessionserver both with using cloudflare and google dns servers... The error seems to be the java excerpt I posted above. I looked into the matter and there is literally no way of solving the issue on Window using pure Java. If we decide it to be worth the effort I could write a C lib and do some JNI magic... However I'm not familiar with Maven at all and don't know how I tell Maven to compile this mess.

mastercoms commented 5 years ago

That can be done later, but for now, I think what I proposed above is fine.

mastercoms commented 5 years ago

Superseded by https://github.com/GlowstoneMC/Glowstone/commit/d486808b2c2f78da5d00aef1f33b90dff4970255.