JoeFoxe / Hexerei-1.18

20 stars 12 forks source link

Server Hang when trying to spawn entities during worldgen. #10

Closed marchermans closed 2 years ago

marchermans commented 2 years ago

Hello,

We had a server hangup during worldgen. Based on the threaddump it looks like you are looking up the tile entities in an area, this can cause hangups.

at java.base@17.0.1/jdk.internal.misc.Unsafe.park(Native Method)
        at java.base@17.0.1/java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:252)
        at TRANSFORMER/minecraft@1.18.1/net.minecraft.util.thread.BlockableEventLoop.m_5667_(BlockableEventLoop.java:146)
        at TRANSFORMER/minecraft@1.18.1/net.minecraft.util.thread.BlockableEventLoop.m_18701_(BlockableEventLoop.java:136)
        at TRANSFORMER/minecraft@1.18.1/net.minecraft.server.level.ServerChunkCache.m_7587_(ServerChunkCache.java:132)
        at TRANSFORMER/minecraft@1.18.1/net.minecraft.world.level.Level.m_6522_(Level.java:170)
        at TRANSFORMER/minecraft@1.18.1/net.minecraft.world.level.LevelReader.m_46819_(LevelReader.java:122)
        at TRANSFORMER/minecraft@1.18.1/net.minecraft.world.level.Level.m_6325_(Level.java:165)
        at TRANSFORMER/hexerei@0.1.13/net.joefoxe.hexerei.util.HexereiUtil.getTileEntitiesAroundPosition(HexereiUtil.java:97)
        at TRANSFORMER/hexerei@0.1.13/net.joefoxe.hexerei.util.HexereiUtil.getAllTileEntityPositionsNearby(HexereiUtil.java:69)
        at TRANSFORMER/hexerei@0.1.13/net.joefoxe.hexerei.events.SageBurningPlateEvent.onEntityJoin(SageBurningPlateEvent.java:56)
        at net.minecraftforge.eventbus.ASMEventHandler_880_SageBurningPlateEvent_onEntityJoin_CheckSpawn.invoke(.dynamic)
        at MC-BOOTSTRAP/eventbus@5.0.3/net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85)
        at MC-BOOTSTRAP/eventbus@5.0.3/net.minecraftforge.eventbus.EventBus$$Lambda$4067/0x000000080164cef8.invoke(Unknown Source)
        at MC-BOOTSTRAP/eventbus@5.0.3/net.minecraftforge.eventbus.EventBus.post(EventBus.java:302)
        at MC-BOOTSTRAP/eventbus@5.0.3/net.minecraftforge.eventbus.EventBus.post(EventBus.java:283)
        at TRANSFORMER/forge@39.0.58/net.minecraftforge.event.ForgeEventFactory.canEntitySpawn(ForgeEventFactory.java:203)
        at TRANSFORMER/forge@39.0.58/net.minecraftforge.common.ForgeHooks.canEntitySpawn(ForgeHooks.java:1076)
        at TRANSFORMER/minecraft@1.18.1/net.minecraft.world.level.NaturalSpawner.m_47038_(NaturalSpawner.java:181)
        at TRANSFORMER/minecraft@1.18.1/net.minecraft.world.level.NaturalSpawner.m_47045_(NaturalSpawner.java:124)
        at TRANSFORMER/minecraft@1.18.1/net.minecraft.world.level.NaturalSpawner.m_47029_(NaturalSpawner.java:114)
        at TRANSFORMER/minecraft@1.18.1/net.minecraft.server.level.ServerChunkCache.m_8490_(ServerChunkCache.java:355)
        at TRANSFORMER/minecraft@1.18.1/net.minecraft.server.level.ServerChunkCache.m_142483_(ServerChunkCache.java:311)
        at TRANSFORMER/minecraft@1.18.1/net.minecraft.server.level.ServerLevel.m_8793_(ServerLevel.java:278)
        at TRANSFORMER/minecraft@1.18.1/net.minecraft.server.MinecraftServer.m_5703_(MinecraftServer.java:868)
        at TRANSFORMER/minecraft@1.18.1/net.minecraft.server.dedicated.DedicatedServer.m_5703_(DedicatedServer.java:328)
        at TRANSFORMER/minecraft@1.18.1/net.minecraft.server.MinecraftServer.m_5705_(MinecraftServer.java:808)
        at TRANSFORMER/minecraft@1.18.1/net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:668)
        at TRANSFORMER/minecraft@1.18.1/net.minecraft.server.MinecraftServer.m_177918_(MinecraftServer.java:258)
        at TRANSFORMER/minecraft@1.18.1/net.minecraft.server.MinecraftServer$$Lambda$18189/0x0000000802e2f5d0.run(Unknown Source)
        at java.base@17.0.1/java.lang.Thread.run(Thread.java:833)
LegendaryTot commented 2 years ago

I think this is related to #7

Here's a spark profiler showing similar issue: https://spark.lucko.me/k3preh2LJm

max2000383 commented 2 years ago

Hey, I'm having a similar issue, and am working on a fork to improve the tile search, but in the meantime, a really, really fast hotfix that would help this would be just adding a check for if sage has any range in https://github.com/JoeFoxe/Hexerei-1.18/blob/main/src/main/java/net/joefoxe/hexerei/events/SageBurningPlateEvent.java

        //new line here
        if(HexConfig.SAGE_BURNING_PLATE_RANGE.get()==0)return;

        List<BlockPos> nearbySageBurningPlates = HexereiUtil.getAllTileEntityPositionsNearby(ModTileEntities.SAGE_BURNING_PLATE_TILE.get(), HexConfig.SAGE_BURNING_PLATE_RANGE.get() + 1, world, entity);

        if (nearbySageBurningPlates.size() == 0) {
            return;
        }

If you add that line, then at least people that disable sage burning working at all won't get swamped during large world spawns. I'm taking a look at what that other helpful dude said in the other issue, but i would really appreciate it if you pushed this tiny change as a stopgap. I really want to run your mod in my modpack, I have some friends that really love what you've done.

Tyrius1 commented 2 years ago

https://pastebin.com/DT8YSjgr looks like the same thing but sharing just in case it helps.

JoeFoxe commented 2 years ago

Awesome! Thank you for the tips and for working on a fork haha, I have been taking some mental time off which is why I havent been replying to much but I will start to work on it again more now

max2000383 commented 2 years ago

I can't continue work on the fork, but the best advice i didn't implement is just having a static list of positions by world of currently burning sage entities and checking if any of those entities were near enough instead of exhaustively by chunk.

JoeFoxe commented 2 years ago

hopefully fixed up in the latest version, if not you can disable it via configs