WorldGen Deadlock
Original Paper issue reported: https://github.com/PaperMC/Paper/issues/4272
WorldGenRegion::startsForFeature(n.m.c.SectionPos,n.m.w.l.l.f.StructureFeature)
is leaking access to the actual World object instead of the WorldGenRegion object by accessing world.getStructureManager()
The WorldGenRegion needs to call StructureFeatureManager::forWorldGenRegion(n.m.s.l.WorldGenRegion) and store that in the WorldGenRegion instance and then startsForFeature needs to use that reference instead.
With this bug, main thread blocks asking for a chunk, chunk goes to world generation, world generation then asks for a structure, hits real world object which does a .join on the getChunk to wait for main thread to generate the chunk.
But because main thread is blocked, and the world gen thread is blocked, this dependent chunk can never be completed, resulting in a deadlock and the server crashes.
Created Issue:
WorldGen Deadlock
Original Paper issue reported: https://github.com/PaperMC/Paper/issues/4272
WorldGenRegion::startsForFeature(n.m.c.SectionPos,n.m.w.l.l.f.StructureFeature)
is leaking access to the actual World object instead of the WorldGenRegion object by accessing world.getStructureManager()
The WorldGenRegion needs to call StructureFeatureManager::forWorldGenRegion(n.m.s.l.WorldGenRegion) and store that in the WorldGenRegion instance and then startsForFeature needs to use that reference instead.
With this bug, main thread blocks asking for a chunk, chunk goes to world generation, world generation then asks for a structure, hits real world object which does a .join on the getChunk to wait for main thread to generate the chunk.
But because main thread is blocked, and the world gen thread is blocked, this dependent chunk can never be completed, resulting in a deadlock and the server crashes.
Gee I wonder who made Paper
Anyway, the issue was found when patching the vanilla server. It's always better to have this fixed upstream as it affects everyone, not just users of Paper.
Relates to MC-199487 and MC-246262 (same/similar root cause)
Analysis (yarn mapping):
This is another "getChunk during worldgen" deadlock. (Not an infinite loop.) Entity#readNbt (ayl.g, L1687) is a method that reads a NBT compound and sets an entity's fields. (While I could not figure out which entity it is, One of the operations include Entity#setPos (aly.o, L3212) which sets the new position of an entity and calls several callbacks. One of the callbacks called is EntityGameEventHandler#onEntitySetPos (cvx.a, L34), which calls EntityGameEventHandler#updateDispatcher (cvx.a, L46), a method that queries the chunk for the new position of the entity. This uses the getChunk method.
Since the chunk queried is currently generating, getChunk never returns until the chunk is fully generated. However, since the getChunk call is part of the chunk generation, getChunk must return to fully generate the chunk. This obviously causes a deadlock.
Is this a Paper only issue or a Vanilla issue? If it's not Vanilla, then it's invalid here and should be brought up to the creators of Paper.
I am a creator of Paper, It is a vanilla issue.
Sorry for my very un-educated approach at this subject, I will try to learn more before giving out a random statement.
Please keep discussions on-topic. Off-topic comments and chatter may be hidden to avoid clutter, enabling us to focus on the information relevant to the bug.
papers patch (MIT):
https://github.com/PaperMC/Paper/commit/819ff324354b61a2656fa0d8129275475478ccc1
does this mean there's going to be a 1.16.4? :o
No need to comment on resolved issues especially for unrelated questions, but yes.
Why the fix version is shown 1.16.4 Pre-release 1? not Future version 1.16+? 1.16.4 Pre-release 1 is still not released.
So what? It will be in it when it is.
Is there a specific way to trigger this, or does it just happen randomly? Does it only happen with custom world gen?
If I recall correctly it happens with certain shaders and AMD graphics cards, particularly when changing dimensions through portals.
Incorrect, it is a server side bug that generating chunks if the right scenarios come into play, will crash the server.