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

Possible rare concurrency issue may cause changes in chunk to be reverted

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Resolution: Fixed
    • Affects Version/s: Minecraft 1.10.2, Minecraft 1.12.2
    • Fix Version/s: Minecraft 1.13.2
    • Labels:
      None
    • Confirmation Status:
      Unconfirmed
    • Category:
      (Unassigned)

      Description

      Note: I've never seen it happen in vanilla. This is purely based on code analysis and tests with artificial delay in one place in the code. I found it while working on a mod.

      When Minecraft saves a chunk there is a brief moment when that chunk is neighter loaded, nor queued for saving, nor saved, and access to region file isn't blocked. Since saving chunks is done in separate thread, it is possible that loading a chunk that is currently being saved but not yet being written to disk loads old version or if there is none - regenerates that chunk.

      The problem in code, based on decompiled source from MCP 9.30 and forge 1.10.2 decompiled source, taking patches into account (ignoring forge specific code):

      AnvilChunkLoader.loadChunk checks if the chunk is in chunksToRemove map to see if it's unloaded and waiting to be saved.
      AnvilChunkLoaded.writeNextIO removes the chunk it writes to disk before it starts writing the data. The time between removing that chunk from chunksToRemove and starting writing it to disk is usually very short so it's almost impossible to see it in practice.

      To test if it really is possible I added artificial delay in that place and added code to check if the same chunk is generated more than once. After a few minutes of flying around I got a few chunks that generated more than once.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            Barteks2x Bartosz Skrzypczak
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: