mojira.dev
MC-73207

Minecraft server list displays "Can't connect to server" on startup

The bug

Whenever I start my game and go onto the Multiplayer server list, the servers all say "Can't connect to server" but when I refresh the page, it says the normal servers MOTD in the listing.

Code analysis (MCP names), comments, and additional note by @unknown

I've analyzed the issue and found it's a race condition with the multi-threaded server pinger code. The server pinging code (net.minecraft.client.network.ServerPinger) is run in multiple threads, and each thread calls net.minecraft.network.NetworkManager.createNetworkManagerAndConnect(). This function uses "lazy loaders" (net.minecraft.util.LazyLoadBase) to initialize some static variables. The issue lies in net.minecraft.util.LazyLoadBase.getValue(). This function is not thread-safe. Below you'll find the code in question with comments explaining exactly what is happening and how to fix it.

package net.minecraft.util;

public abstract class LazyLoadBase<T>
{
    private T value;
    private boolean isLoaded;

    public T getValue() // NOT THREAD-SAFE. SIMPLE FIX: declare the method synchronized
    {
        if (!this.isLoaded) // Thread 1: Condition is true; Thread 2: Condition is false
        {
            this.isLoaded = true; // Thread 1: SETS isLoaded to true, BUT VALUE IS STILL NULL
            this.value = this.load();
        }

        return this.value; // Thread 2: RETURNS NULL because this.load() is not finished in Thread 1
    }

    protected abstract T load();
}

Note that depending on the speed of the computer, this bug might not occur. If the first thread finishes quickly enough everything will appear normal.

Linked issues

Attachments

Comments

kumasasa

Is this still an issue in the current Minecraft Snapshot 15w47c or later? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.

MyzelYam

Confirmed for 1.9, but it doesn't always happen and it doesn't necessarily happen to all server entries. (Using win10 java8)
Refreshing indeed solves the problem. This has been happening to me for quite a while, also in 1.8.
http://imgur.com/gSYX5Fb

user-f2760

The enviroment is supposed to contain pc details.

Kyle Repinski

Really annoying that this hasn't been fixed. It would take less than a minute with the information I provided.

Muhammet Kurt

Error of my Minecraft of 'Minecraft game output' : (On pingin the servers)

16:55:58	byh	Can't ping mc.cubecraftgames.net: Timed out
16:55:58	byh	Can't ping mc.candycraft.net: Timed out
16:55:58	byh	Can't ping mc.craftrise.tc: Timed out
16:55:58	byh	Can't ping mc.hypixel.net: Timed out
16:59:08	byh	Can't ping play.legendcrafttr.com: Internal Exception: java.io.IOException: Varolan bir baglanti uzaktaki bir ana bilgisayar tarafindan zorla kapatildi

Minecraft Version: SnapShot: 18w01a

Muhammet Kurt

OMG! Finally this is fixed on SnapShot 18w02a.
On start Minecraft and click on the multiplayer, all servers is dislay online (if server is online).
Thanks for fix this bug in 18w02a SnapShot!

Daniel Orr

Absolutely hate this bug. Probably my OCD lol 😛
But it really annoys me when I have to reload them to see the MOTD

wobst.michael

Appears to be fixed for me in 18w02a, too.

SpongerDanger

(Unassigned)

Confirmed

multiplayer, server-list

Minecraft 1.8, Minecraft 1.9, Minecraft 1.10.2, Minecraft 16w41a, Minecraft 16w42a, Minecraft 1.11.2, Minecraft 1.12.2, Minecraft 17w50a

Minecraft 18w02a

Retrieved