mojira.dev
MC-168666

GS4 query / net.minecraft.server.MinecraftServer.getPlayerNames() is not thread-safe

The bug

net.minecraft.server.MinecraftServer.getPlayerNames() (Mojang name) is not thread-safe. This can be problematic because it implements net.minecraft.server.ServerInterface.getPlayerNames() for the DedicatedServer. That method is called from a different thread when using GS4 query, see QueryThreadGs4.

Linked issues

Comments 1

Can confirm in 1.21.11:

public String[] e() {
    String[] $$0 = new String[this.k.size()];
    for (int $$1 = 0; $$1 < this.k.size(); ++$$1) {
        $$0[$$1] = this.k.get($$1).gI().name();
    }
    return $$0;
}

The underlying player collection is declared as:

private final List<axg> k = Lists.newArrayList();

If a player joins or leaves on the main server thread at the exact moment the query thread is iterating, the ArrayList can resize or shift mid loop, triggering IndexOutOfBoundsException and silently crashing the query thread.

Marcono1234

(Unassigned)

Community Consensus

Platform

Low

Crash, Networking

1.15.1, 1.21.11

Retrieved