Server handshake race condition can cause client to deadlock

Author: IzzelAlizCreated Jul 22, 2022Updated Apr 3, 2026
LabelsBugTriage1.181.19

Minecraft Version: 1.18.2

Forge Version: 40.1.59

Logs: https://gist.github.com/IzzelAliz/f10e933a280b3393db24fa6f85ee606a

Steps to Reproduce:

  1. Have a mod disconnect clients in LoadFromFile event (easiest case to reproduce) at server side
  2. Connect to server and get kicked
  3. Connect again, login forever

Description of issue:

The Forge sync registries in LOGIN phase when joining a server, and revert the registries to frozen when disconnected.

However, Forge client only reverts the registry when there is a level loaded, and there are a lot of things can happen between client loaded the registry and client loaded a level(when ClientboundLoginPacket is received). If the client get kicked/disconnect in this not short period of time, it will not revert the registry. There are many chance that client can get disconnected, like random login packets from other mods, PlayerNegotiationEvent, PlayerEvent.LoadFromFile, and more.

When client joines a server with registry not reverted, the client will load registry from server during LOGIN and throw an exception. The count down latch here will not count down, so the netty thread is deadlocked (Netty Client IO #8 in logs). The client now display a connecting screen forever. If you click the "Disconnect" button, the gui will deadlock too because the render thread is joining netty thread (Render thread in logs).

https://github.com/MinecraftForge/MinecraftForge/blob/18f5bdb7ca2290549bc46a22f760a098258228bd/src/main/java/net/minecraftforge/network/HandshakeHandler.java#L292-L309

This should affect all Minecraft versions after 1.13 upgrade.

Source: MinecraftForge/MinecraftForge