Skip to content

Fix disconnect when recording during a server switch - #65

Open
lucasfrederico wants to merge 1 commit into
Moulberry:masterfrom
lucasfrederico:fix/entity-id-before-assignment
Open

Fix disconnect when recording during a server switch#65
lucasfrederico wants to merge 1 commit into
Moulberry:masterfrom
lucasfrederico:fix/entity-id-before-assignment

Conversation

@lucasfrederico

Copy link
Copy Markdown

We run a Minecraft network (LoverFella) behind Velocity. Staff who record with Flashback get disconnected when the proxy moves them between backend servers. Two reports so far, both with the same stack:

java.lang.IllegalStateException: Tried to access entity ID before ID assignment
	at net.minecraft.world.entity.Entity.getId(Entity.java:438)
	at com.moulberry.flashback.record.Recorder.writePacketAsync(Recorder.java:898)
	at net.minecraft.network.Connection.handler$bgb000$flashback$genericsFtw(Connection.java:1749)
	at net.minecraft.network.Connection.channelRead0(Connection.java:167)

Flashback 0.42.1, Minecraft 26.2, Fabric.

writePacketAsync null-checks the local player before calling getId(), but getId() throws when the entity has not been assigned an id yet, so non-null is not enough. On a proxy the client has already built the LocalPlayer for the server it is being sent to while packets for it are still arriving, which lands inside that window. The exception goes up through channelRead0 and the client drops the connection with a packet handling error.

Both of our reports happened inside our scheduled restart window, which is exactly when players get moved between backends.

The patch catches the exception and falls back to -1. No real entity id matches that, so the two filters below simply do not match and the packet is recorded like any other. Recording two packets that would otherwise be skipped seemed better than losing the connection.

Entity.getId() throws IllegalStateException if the entity has no id assigned
yet. The null check on the local player isn't enough to make the call safe:
on a proxied network the client builds the LocalPlayer for the new backend
while packets are still coming in, so there's a window where the player is
non-null but has no id.

The exception escapes channelRead0 and the client disconnects with a Packet
handling error. Catching it and treating an unassigned id as not-the-local-
player keeps the packet and the connection.
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 this pull request may close these issues.

1 participant