The bug
The RCON protocol is based on TCP, which is designed to transmit a stream of individual bytes. If you send 100 bytes at once, they won't necessarily be received as a unit of exactly those 100 bytes. You might get 80 bytes first and then the remaining 20 bytes. Or get more than 100 bytes, if more data has already arrived. Yet Minecraft's RCON implementation assumes the chunks of the TCP stream it receives correspond exactly to RCON packets and if that is not the case closes the socket, see net.minecraft.server.rcon.thread.RconClient.run()
(Mojang name).
In practice, it mostly works if you send commands slowly, like a human entering them in real time. But if you want to send (automated) commands in bulk the server soon reads less or more than the expected amount of data and closes the socket. The only way to get any kind of reliability is to wait for the response to arrive before sending the next command, forcing a round trip for every command.
How to reproduce
Start a local server with the following
server.properties
settings:enable-rcon=true rcon.port=25575 rcon.password=test
Run the attached Java code
Java 11(\\+)
java .\RconTest.java localhost 25575 test
Pre Java 11
javac .\RconTest.java java RconTest localhost 25575 test
❌ It will throw an exception pretty soon after executing the first commands
Linked issues
relates to 1
Attachments
Comments 6
@@unknown: Under MC-72390, I have a PoC script that is tested and, via Rcon, will crash a server with a ConcurrentModificationException; though I'm not sure if that bug is caused by this one. They're almost certainly related, however.
@@unknown: do you have further details about how this issue relates to MC-72390?
@@unknown: I managed to make a quick hack in Java (which I don't normally use a lot, so I'm not going to make a full-fledged client). I'm attaching it. Be sure to set the static variables in the source.
@@unknown: This is unrelated to MC-72390. They're just both more problematic the more you send.
Is this still a issue in the latest version of the game(currently 1.13.1)?
If so, please add it to the affected versions, thanks!
Is this considered fixed? It seems that I'm having a similar issue while trying to send two packets directly one after another (in one binary blob) - my connection is instantly dropped. The issue does not happen if the packets are separated by some physical time. (Happening on 1.13.2)
proof of concept that breaks it?