Skip to content

Fix chat race condition#1042

Merged
electronicboy merged 4 commits into
PaperMC:dev/3.0.0from
EpicPlayerA10:fix/chat-race-condition
Jan 11, 2024
Merged

Fix chat race condition#1042
electronicboy merged 4 commits into
PaperMC:dev/3.0.0from
EpicPlayerA10:fix/chat-race-condition

Conversation

@EpicPlayerA10
Copy link
Copy Markdown
Contributor

@EpicPlayerA10 EpicPlayerA10 commented Jul 11, 2023

The issue

Chat system in velocity has a race condition. When player is sending messages very fast, then a backend server will kick him for out-of-order chat.

You can test this by installing litematica mod and use the feature called Paste schematic into world. Then litematica will send commands very fast and then you get kicked from the proxy. This issue only happens when player is connected to the proxy. When you are connected to the minecraft server directly then the issue disappears.

The race condition looks like this:

Flowchart before

Flowchart before

You can see here that velocity doesn't wait for packet to be sent. The chat gets out of sync and thats why players are getting kicked from backend server.

Fix

This pull request fixes it by waiting for packets to be sent. Now the flowchart looks like this:

Flowchart after

Flowchart after

Related issues

@electronicboy
Copy link
Copy Markdown
Member

Don't have hardware to look into this properly, but on the surface, this looks much closer to how I said this stuff should probably work in the first place

@intersecato
Copy link
Copy Markdown

intersecato commented Aug 21, 2023

Hi @EpicPlayerA10 @electronicboy,
we were able to test the fix in production with various users. The problem seems to persists but more rarely.
We will try to investigate the problem further.

image

@EpicPlayerA10
Copy link
Copy Markdown
Contributor Author

The problem seems to persists but more rarely.

Okay, now the latest commit will ensure that chat packets are fully sent. This should get rid of this problem.

@intersecato
Copy link
Copy Markdown

intersecato commented Aug 29, 2023

Okay, now the latest commit will ensure that chat packets are fully sent. This should get rid of this problem.

The problem is still there. A player reported me about a kick again today.

@EpicPlayerA10
Copy link
Copy Markdown
Contributor Author

The problem is still there. A player reported me about a kick again today.

Hmm. I don't know why this is still happening. I have no idea. I think that i did everything correct.

@electronicboy electronicboy self-assigned this Oct 12, 2023
@CatTeaA
Copy link
Copy Markdown

CatTeaA commented Jan 4, 2024

Is there any progress? Looking forward to it

@electronicboy
Copy link
Copy Markdown
Member

I recall looking over this a few times and it generally looked fine, finally have hardware to test, just time; if this can be rebased, I'll try and get to this on the weekend or sometime next week

@EpicPlayerA10
Copy link
Copy Markdown
Contributor Author

Rebased

@demxn013
Copy link
Copy Markdown

this issue still exists on 1.20 paper backend server on client version 1.21. Im using the most recent version of velocity.
It only happens with commands though.
image

A248 pushed a commit to A248/Velocity that referenced this pull request Apr 12, 2026
@7wOv6ySCjo
Copy link
Copy Markdown

The bug is still occurring in version 26.1.2
We get the error: ‘keepalive: time out (out of order!)’
Several disconnections a day for various players.

I'm not entirely sure whether it's an ‘out of order’ error with keepalive packets or with the chat specifically. The strange thing is that you don't even need to type commands or send messages in the chat; just exploring the world for a few minutes is enough to trigger this ‘timeout’ error.

@EpicPlayerA10
Copy link
Copy Markdown
Contributor Author

The bug is still occurring in version 26.1.2 We get the error: ‘keepalive: time out (out of order!)’ Several disconnections a day for various players.

I'm not entirely sure whether it's an ‘out of order’ error with keepalive packets or with the chat specifically. The strange thing is that you don't even need to type commands or send messages in the chat; just exploring the world for a few minutes is enough to trigger this ‘timeout’ error.

Can you send a screenshot of this error?

@WouterGritter
Copy link
Copy Markdown
Contributor

@7wOv6ySCjo could you check and confirm whether #1782 solves this issue for you or not?

@7wOv6ySCjo
Copy link
Copy Markdown

The bug is still occurring in version 26.1.2 We get the error: ‘keepalive: time out (out of order!)’ Several disconnections a day for various players.
I'm not entirely sure whether it's an ‘out of order’ error with keepalive packets or with the chat specifically. The strange thing is that you don't even need to type commands or send messages in the chat; just exploring the world for a few minutes is enough to trigger this ‘timeout’ error.

Can you send a screenshot of this error?

Captura de pantalla (8136)

This usually happens with entity ID number 1, as it doesn’t happen as often with subsequent entities ID, but it still disconnects the user.

I investigated the code and the line causing the disconnection is in: net.minecraft.server.network.ServerCommonPacketListenerImpl

            LOGGER.info("Disconnecting {} for sending keepalive response ({}) out-of-order!", this.playerProfile().name(), packet.getId());
            //this.disconnectAsync(TIMEOUT_DISCONNECTION_MESSAGE, io.papermc.paper.connection.DisconnectionReason.TIMEOUT);
            
            and
            
    LOGGER.info("Disconnecting {} for sending keepalive response ({}) without matching challenge!", this.playerProfile().name(), packet.getId());
    //this.disconnectAsync(TIMEOUT_DISCONNECTION_MESSAGE, io.papermc.paper.connection.DisconnectionReason.TIMEOUT);

I simply commented out those two disconnection lines and that was it; I no longer lose users due to arbitrary disconnections, although I don’t know what the consequences of preventing this disconnection might be.

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.

8 participants