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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: Minor 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)
           Stack:
                   [email protected]/jdk.internal.misc.Unsafe.park(Native Method)
                   [email protected]/java.util.concurrent.locks.LockSupport.park(LockSupport.java:211)
                   [email protected]/java.util.concurrent.CompletableFuture$Signaller.block(CompletableFuture.java:1864)
                   [email protected]/java.util.concurrent.ForkJoinPool.unmanagedBlock(ForkJoinPool.java:3463)
                   [email protected]/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3434)
                   [email protected]/java.util.concurrent.CompletableFuture.waitingGet(CompletableFuture.java:1898)
                   [email protected]/java.util.concurrent.CompletableFuture.join(CompletableFuture.java:2117)
                   net.minecraft.world.level.chunk.storage.IOWorker.a(SourceFile:84)
                   net.minecraft.world.level.chunk.storage.IChunkLoader.f(IChunkLoader.java:136)
                   net.minecraft.server.level.PlayerChunkMap.j(PlayerChunkMap.java:978)
                   net.minecraft.server.level.PlayerChunkMap.lambda$21(PlayerChunkMap.java:582)
                   net.minecraft.server.level.PlayerChunkMap$$Lambda$6319/0x0000000801dd14c8.get(Unknown Source)
                   [email protected]/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
                   net.minecraft.util.thread.IAsyncTaskHandler.c(SourceFile:151)
                   net.minecraft.server.level.ChunkProviderServer$b.c(ChunkProviderServer.java:634)
                   net.minecraft.util.thread.IAsyncTaskHandler.y(SourceFile:125)
                   net.minecraft.server.level.ChunkProviderServer$b.y(ChunkProviderServer.java:645)
                   net.minecraft.util.thread.IAsyncTaskHandler.c(SourceFile:134)
                   net.minecraft.server.level.ChunkProviderServer.a(ChunkProviderServer.java:163)
                   net.minecraft.world.level.World.a(World.java:283)
                   net.minecraft.world.level.IWorldReader.a(SourceFile:140)
                   net.minecraft.world.level.World.d(World.java:277)
                   net.minecraft.world.level.World.l(World.java:272)
                   net.minecraft.world.level.World.b_(World.java:609)
                   net.minecraft.world.entity.Entity.l(Entity.java:1325)
                   net.minecraft.world.entity.Entity.an(Entity.java:573)
                   net.minecraft.world.entity.EntityLiving.an(EntityLiving.java:388)
                   net.minecraft.world.entity.Entity.k(Entity.java:539)
                   net.minecraft.world.entity.EntityLiving.k(EntityLiving.java:2767)
                   net.minecraft.world.entity.player.EntityHuman.k(EntityHuman.java:260)
                   net.minecraft.server.level.EntityPlayer.l(EntityPlayer.java:621)
                   net.minecraft.server.network.PlayerConnection.b(PlayerConnection.java:299)
                   net.minecraft.network.NetworkManager.a(NetworkManager.java:250)
                   net.minecraft.server.network.ServerConnection.c(ServerConnection.java:172)
                   net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1326)
                   net.minecraft.server.dedicated.DedicatedServer.b(DedicatedServer.java:428)
                   net.minecraft.server.MinecraftServer.a(MinecraftServer.java:1210)
                   net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1037)
                   net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:306)
                   net.minecraft.server.MinecraftServer$$Lambda$4090/0x00000008013d8860.run(Unknown Source)
                   [email protected]/java.lang.Thread.run(Thread.java:833)

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

              Created:
              Updated:
              Resolved: