Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-6871

Not a Spigot bug: Server may deadlock when trying to load a new world and teleport a player to it



    • Bug
    • Resolution: Invalid
    • Minor
    • None
    • None
    • Production env: Ubuntu 20.04, Java 17.0.1, Test env: macOS 11.5.2, Java 17.0.1

    • git-Spigot-8965a50-0ba6b90 (MC: 1.18.1)
    • Yes


      I have a plugin that manages worlds that belong to players.  Each player has their own world and can invite their friends to it and decide who can or can't build, etc.  Majority of these worlds are superflat worlds.

      When a player tries to go to their world, my plugin will check if the world is currently loaded.  If it is not currently loaded, it will load the world using WorldCreator, with spawn chunks kept in memory set to false.  Then it will teleport the player to their world.

      On version: git-Spigot-8965a50-0ba6b90 (MC: 1.18.1) (currently the latest as of this post)

      I have made a single change to the server jar: Added true || inside the first if statement in MinecraftServer.prepareLevels as there isn't a way to make getKeepSpawnInMemory() return false until after creating the world, and a World object is not returned until after spawn chunks have already started loading.  I have been doing this for years to make worlds load quicker without the unnecessary preload of spawn chunks.  I never knew about the WorldInitEvent before, I'm going to try setting keepSpawnInMemory to false using this method instead, and I will update here on whether the server still crashes or not.  (See update below)  It may be a good idea to indicate the existence of WorldInitEvent in the documentation for WorldCreator.createWorld().

      The problem: Sometimes (maybe 1 out of every 50?) the main thread will get stuck, it appears it might be waiting on a chunk to load.  When the main thread gets stuck, when I do a stack dump I can see the IO-Worker threads are not doing anything at all.  The IO-Worker threads never appear in the crash report though.

      Update: After starting to use WorldInitEvent instead of modifying the server jar to prevent spawn chunks from loading, the server still exhibits this bug.

      Update 2: I found this bug only ever manifests itself after loading the world, then unloading the world, and then loading it again. It will never trigger on the first load of the world.

      Update 3: Turns out it was my fault – I made a change in the way my plugin handled world loading and unloading.  It was reusing an old World object.

      This did not happen in 1.17.1 versions.

      Stack trace is below:

      Current Thread: Server thread
           PID: 43 | Suspended: false | Native: false | State: WAITING
           Thread is waiting on monitor(s):
                   Locked on:net.minecraft.server.network.ServerConnection.c(ServerConnection.java:172)
                   java.base@17.0.1/jdk.internal.misc.Unsafe.park(Native Method)
                   net.minecraft.server.level.PlayerChunkMap$$Lambda$6319/0x0000000801dd14c8.get(Unknown Source)
                   net.minecraft.server.MinecraftServer$$Lambda$4090/0x00000008013d8860.run(Unknown Source)




            Unassigned Unassigned
            Siggi88 Sigurður
            0 Vote for this issue
            1 Start watching this issue