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

Rcon is not thread-safe

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Minecraft 1.8, Minecraft 1.8.8, Minecraft 15w43c, Minecraft 15w44a, Minecraft 15w44b, Minecraft 15w45a, Minecraft 15w46a, Minecraft 15w47c, Minecraft 16w07b, Minecraft 1.9 Pre-Release 1, Minecraft 1.9 Pre-Release 2, Minecraft 1.9, Minecraft 1.10.2, Minecraft 1.11 Pre-Release 1, Minecraft 1.11.2, Minecraft 17w17b, Minecraft 1.12, Minecraft 17w43b, Minecraft 1.13, Minecraft 1.14.1
    • Community Consensus
    • (Unassigned)

      Use of Rcon to execute commands that modify server state causes a race condition that may result in a java.util.ConcurrentModificationException in the main server thread if a command modifies data during a server tick.

      Conversely, executing commands via Rcon that iterate over internal data structures (such as /save-all) may cause a java.util.ConcurrentModificationException in the Rcon thread if the main thread modifies those structures (see MC-68374).

      Update 2016-11-08

      During reproduction of this bug, it was observed that introducing a small delay (as low as 0.003 seconds) between each command sent via rcon appears to greatly reduce the chance-per-command of the bug being triggered. However, with zero delay between commands being sent, the chance of the bug being triggered is significant, with usually less than 100 commands being enough to trigger the bug.

      End update

      In the following example, an external script was being used to run commands. A ConcurrentModificationException was thrown when the Rcon thread /summon ed a Creeper and added it to the world's entities list, while the main thread was simultaneously iterating over the same list due to a command block executing /kill @e[type=MinecartTNT] . (Full crash report is attached)

      [2014-09-26 21:14:21] [RCON Client #3/INFO]: $SERVCMD Rcon: effect RobotoRaccoon 11 60 100 true
      [2014-09-26 21:14:21] [RCON Client #3/INFO]: [Rcon: Given Resistance (ID 11) * 100 to RobotoRaccoon for 60 seconds]
      [2014-09-26 21:14:21] [RCON Client #3/INFO]: $SERVCMD Rcon: playerinfo RobotoRaccoon
      [2014-09-26 21:14:21] [RCON Client #3/INFO]: $SERVCMD Rcon: summon Creeper 2209 86 501 {Fuse:0}
      [2014-09-26 21:14:21] [RCON Client #3/INFO]: [Rcon: Object successfully summoned]
      [2014-09-26 21:14:21] [Server thread/ERROR]: Encountered an unexpected exception
      u: Executing command block
              at net.minecraft.server.MinecraftServer.z(SourceFile:603) ~[minecraft.jar:?]
              at po.z(po.java:228) ~[minecraft.jar:?]
              at net.minecraft.server.MinecraftServer.y(SourceFile:531) ~[minecraft.jar:?]
              at net.minecraft.server.MinecraftServer.run(SourceFile:447) [minecraft.jar:?]
              at java.lang.Thread.run(Unknown Source) [?:1.7.0_55]
      Caused by: java.util.ConcurrentModificationException
              at java.util.ArrayList$Itr.checkForComodification(Unknown Source) ~[?:1.7.0_55]
              at java.util.ArrayList$Itr.next(Unknown Source) ~[?:1.7.0_55]
              at aqu.a(SourceFile:2230) ~[minecraft.jar:?]
              at ah.a(SourceFile:433) ~[minecraft.jar:?]
              at ah.b(SourceFile:136) ~[minecraft.jar:?]
              at ab.a(ab.java:71) ~[minecraft.jar:?]
              at aqf.a(SourceFile:97) ~[minecraft.jar:?]
              at auo.b(SourceFile:53) ~[minecraft.jar:?]
              at qt.a(SourceFile:527) ~[minecraft.jar:?]
              at qt.c(SourceFile:199) ~[minecraft.jar:?]
              at net.minecraft.server.MinecraftServer.z(SourceFile:599) ~[minecraft.jar:?]
              ... 4 more
      [2014-09-26 21:14:21] [Server thread/ERROR]: This crash report has been saved to: /data/minecraft/18-temp/./crash-reports/crash-2014-09-26_21.14.21-server.txt
      [2014-09-26 21:14:21] [RCON Client #3/INFO]: $SERVCMD Rcon: summon Creeper 2209 87 501 {Fuse:0}
      [2014-09-26 21:14:21] [RCON Client #3/INFO]: [Rcon: Object successfully summoned]
      

      Reproduction

      • Create a new Minecraft server instance.
      • Enable Rcon on the default port (25575)
      • Set Rcon password to "test"
      • Connect a Minecraft client to the server.
      • Move the player to x=0, z=0 (or use /spreadplayers 0 0 1 1 false @a) to ensure this location is loaded.
      • Use Python to run the attached rcon.py script, which will send commands to the server (spawning entities at x=0 z=0)
      • The server should crash in under 60 seconds (usually only a few seconds).

      I have successfully reproduced a ConcurrentModificatonException crash using this method. Due to the nature of this bug (race condition), it may take some time before the crash occurs.

            boq [Mojang] Bartosz Bok
            terrorbite TerrorBite
            Votes:
            43 Vote for this issue
            Watchers:
            23 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: