Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-87863

RCON uses TCP as though it's datagram-based

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • Minecraft 1.8.8, Minecraft 15w35e, Minecraft 15w36a, Minecraft 15w36c, Minecraft 1.9.4, Minecraft 1.10, Minecraft 16w41a, Minecraft 16w43a, Minecraft 16w44a, 1.15.1, 1.21
    • None
    • Confirmed
    • Crash, Networking
    • Low
    • Platform

      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

      1. Start a local server with the following server.properties settings:
        enable-rcon=true
        rcon.port=25575
        rcon.password=test
        
      2. Run the attached Java code RconTest.java
        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

        1. MC-87863.png
          MC-87863.png
          251 kB
        2. RconFail.java
          4 kB
        3. RconTest.java
          5 kB

            Unassigned Unassigned
            jonathan2520 jonathan2520
            Votes:
            15 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              CHK: