Sponge kills Ingame Network Thread
ProsperCraft opened this issue ยท 32 comments
https://gist.github.com/ProsperCraft/cf949ac5f993f4f3994f96dbd5af8efa
This is happening in the console, not sure what started it.
logs.zip
well according to sponge every thing is main thread relevand id do :/ I can make a work around but that will result in pretty heavy task execute in the main thread wish can result in lag on large scale structures. (Like a 1000^3 block of network cables)
@mcenderdragon You are trying to load chunks from off thread. Network threads are only for populating a packet's fields, as used in vanilla; when you do task, you add them to the task lists of MinecraftServer class.
Hmm, @mcenderdragon is worldgen from off thread safe in minecraft 1.12?
well I scan for network blocks, I dont know how much of them are loaded as they are build by players. And the addSheduledTask on sponge are broken.
Well this is in there since 1.8 and until sponge I did not have any issues with it ^^ but normaly player build the blocks so the chunks normaly are already generated.
And the addSheduledTask on sponge are broken.
Can you open an issue at https://github.com/SpongePowered/SpongeForge/issues/new for that?
alredy there: SpongePowered/SpongeForge#1999
Ok wow this is absoltilty not telling anybody what happened. I should print the stacktrace somehwere :S
I found the initia crash
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: java.lang.IllegalStateException: CauseStackManager called from off main thread (current='Thread{class=class java.lang.Thread, name=Network-Thread, priority=5, group=net.minecraftforge.fml.common.thread.SidedThreadGroup[name=SERVER,maxpri=10]}', expected='Thread{class=class java.lang.Thread, name=Server thread, priority=5, group=net.minecraftforge.fml.common.thread.SidedThreadGroup[name=SERVER,maxpri=10]}')!
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at org.spongepowered.common.event.SpongeCauseStackManager.enforceMainThread(SpongeCauseStackManager.java:71)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at org.spongepowered.common.event.SpongeCauseStackManager.getCurrentCause(SpongeCauseStackManager.java:85)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at net.minecraft.world.chunk.Chunk.handler$onLoadReturn$zld000(Chunk.java:1893)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at net.minecraft.world.chunk.Chunk.func_76631_c(Chunk.java:861)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at net.minecraftforge.common.chunkio.ChunkIOProvider.syncCallback(ChunkIOProvider.java:105)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at net.minecraftforge.common.chunkio.ChunkIOExecutor.syncChunkLoad(ChunkIOExecutor.java:94)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:118)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at net.minecraft.world.gen.ChunkProviderServer.func_186028_c(ChunkProviderServer.java:89)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at net.minecraft.world.gen.ChunkProviderServer.redirect$onProvideChunkHead$zmc000(ChunkProviderServer.java:669)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at net.minecraft.world.gen.ChunkProviderServer.func_186025_d(ChunkProviderServer.java:135)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at net.minecraft.world.World.func_72964_e(World.java:309)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at net.minecraft.world.World.func_175726_f(World.java:304)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at net.minecraft.world.World.func_175625_s(World.java:5823)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at futurepack.common.network.NetworkManager$1.isValidBlock(NetworkManager.java:33)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at futurepack.common.FPBlockSelector.addBlock(FPBlockSelector.java:187)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at futurepack.common.FPBlockSelector.ab(FPBlockSelector.java:153)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at futurepack.common.FPBlockSelector.block(FPBlockSelector.java:136)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at futurepack.common.FPBlockSelector.selectBlocks(FPBlockSelector.java:98)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at futurepack.common.FPSelectorHelper.getSelector(FPSelectorHelper.java:64)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at futurepack.common.network.NetworkManager.send(NetworkManager.java:92)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at futurepack.common.network.NetworkManager.run(NetworkManager.java:164)
[09:12:03] [Network-Thread/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at java.lang.Thread.run(Thread.java:748)
Great because Sponge always crashes if I scan the world from another thread this crash happened. It seems like the ingame network is not compatible with sponge :/
You aren't "scanning the world", you're literally triggering chunk loads from another thread. You cannot do this and you WILL blow up other mod's code/Vanilla code that is not expecting this. The error is clear as day, all network handlers in 1.10+ are handled on the Netty thread they arrive on but you'll see that Vanilla, almost always, enqueues it back on the main thread. If you do the same, your issue will go away.
Not an issue on Sponge end.
@Zidane he has a separate system to be computed concurrently with world ticks, something like an electricity network.
Not relevant. You cannot load a chunk from another thread no matter the circumstance. End of discussion.
Well the problem is if I do this It can happen I produce of lag of up to a second and this each tick, depending what the player build, I can show you the code if that makes thinks more clear.
https://gist.github.com/mcenderdragon/e9df9b0f4adc69a6bd488f9e9d0319cd
Also it is interesting Vanilla nor another mod ever blew up so far, I guess I am lucky only sponge had issues with this so far.
@mcenderdragon The moral of the story is this game engine is not built for threaded access. Sponge enforces the check so that plugins don't blow up when their code is called from other threads from event listeners that have ended up on said thread. Just because it has been working with Vanilla is by a stroke of luck.
@mcenderdragon Apparently you hit an edge case in which the block you check to select is in ungenerated chunks. My suggestion is that you offer a chunk cache to the network thread every tick, and your network thread check from its exclusive cache to prevent such loading new chunk issues.
Update: Sending packets is not that costly. You can totally send them on main thread, which also avoids synchronization costs.
@mcenderdragon You are trying to load chunks from off thread. Network threads are only for populating a packet's fields, as used in vanilla; when you do task, you add them to the task lists of MinecraftServer class.
Also the thread is name dmmissleading, its ingame network. You can build machines, which use a network, whisc works alot like the real internet, but much simpler. So this is no IO netty threads for Server/client connection, but rather an asyncronous tileentity ticker.
So, I will look into sponge and help fixing this scheduled task thing first, and test again after that is fixed. Thanks for all these information @mcenderdragon!
https://gist.github.com/Reveter/2d75ec4793a96e92119a088697aeaeac
On logging in to the server and going to a base with fp in it.
Once we got away from established stuff, using your parameters, the test worked.
the costly part is this:
FPBlockSelector sel = FPSelectorHelper.getSelector(user.getWorldObj(), user.getBlockPos(), selectorNetwork);
Collection<ParentCoords> machines = sel.getValidBlocks(selectorMachines);
And the Helper is a thread save casher, so I guess I end upp calling this with addSheduled task. However I will most likely add a config option to enforce using the old logic incase soemone build a very complex structure. Thanks you both for helping and discussing this :)
Ok thats harden then I thoeught, because I end up locking the threads to each other way to often, A waits for B and B tries to call notify but both are in a syncronized space so they have to wait...
THis version should fix the issue: 26.3.152
I don't know how to reproduce this, so the only way I could test it is if you push it to curse so we can put it into production on our server and see if it happens again.
Place a researcher in the world, cheat you all researches so you can open it, use the ingame configs to enable research blueprints in creative and then put something in there wish needs neon and support, There dont have to be network cables connced but it will make things more clear. When using network cables to connect T1/T2 modcules and T1 calculators they have to communicate via the them.
Fix: 26.3.153