Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-134667

Async Chunk Gen dangerously adding entities to world async


    • Icon: Bug Bug
    • Resolution: Fixed
    • Minecraft 18w31a
    • Minecraft 1.13
    • None
    • Unconfirmed

      [Developer Report]

      While Async Chunk generation was a great attempt, there is a massive flaw in the logic.

      The last stage on where the Pending/Prototype Chunk is converted to a real Chunk is being done asynchronously.

      This operation modifies the world, by adding entities and tile entities to the world.

      As it should be well known, modifying the world async is not safe.

      It appears attempts was made to make this safer by using synchronization all over the place, but the attempt was not done correctly, and there is still huge risk that the world is going to be modified in unsafe ways.


      Additionally, that synchronization has totally destroyed the server performance, creating blocking conditions on the main thread.

      To resolve this, the final stage of chunk generation needs to be sent back to the main thread.

      However care needs to be made to avoid a deadlock where the current generate method does a future.get().


      I would suggest breaking it up into a 2 part process, so it does .get() on the Pending Chunk which doesn't need to return to main, and then add chunk to the world once it returns.

      This also then removes the need for many synchronization blocks, further improving server stability and performance.

      In an ideal world, the chunk map will only ever be touched synchronously.

            fry [Mojang] Georgii Gavrichev
            aikar Aikar
            4 Vote for this issue
            6 Start watching this issue