Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-5228

Dead entities (removed during chunk unload) not getting removed from the chunk

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • This server is running CraftBukkit version git-Spigot-1981d55-3e7b386 (MC: 1.14.4) (Implementing API version 1.14.4-R0.1-SNAPSHOT)
    • Yes

      Consider a plugin which is spawning entities on chunk load and removing them again at chunk unload. Minimal example plugin for reproduction (this use a specific chunk for testing (-40,-125), but other chunks outside the spawn region should work as well): https://pastebin.com/y5upXSeL

      How to reproduce:

      • Get in the loading range of that chunk: The chunk gets loaded and the entity gets spawned.
      • Now move away from the chunk again: The chunk gets unloaded and the entity gets removed (marked 'dead', so that is gets removed with the next tick).
      • Repeat. A new entity gets spawned whenever the chunk gets loaded, and the entity gets marked dead whenever the chunk gets unloaded again.
      • However: For some reason these dead entities never actually get removed. chunk#getEntities() will keep listing them, accumulating over time.

      When teleporting far away (I assume: once the chunk leaves the caching region around the player and gets actually unloaded), and then coming back, the entities got removed. Restarting the server also removes the entities.

      Getting closer to the chunk (so the chunk enters entity ticking region) and then leaving again has no effect.

      I haven't tested this yet, but if the chunk is inside the caching region of the spawn region, these dead entities might never get cleared up until the next server restart.

       

      I was able to reproduce this on the mentioned 1.14.4 version and the latest 1.14.3 version of Spigot. I don't know whether this affects vanilla as well.

      I also don't know yet whether this only affects entities removed during the chunk unload event, or whether the non-AI or non-persistent attributes of the spawned mob play a role in this issue. And I haven't checked yet whether the entities are also still listed by world#getEntities, or whether this only affects chunk#getEntities.

      (I still have to do some more testing on this)

       

      Edit: Just noticed that this also affects the World#rayTraceEntities API function, which retrieves the entities from the individual chunks in range and therefore is likely to return these dead entities as well (if not explicitly filtered by the plugin).

      Edit: This can also lead to performance issues related to spawning new entities, ticking entities, and related to memory issues, because the number of these non-removed dead entities can climb into the thousands quite quickly. In timings this can for example show up as the server spending lots of time ticking entities, even though the number of entities appears to be quite low.

            Unassigned Unassigned
            blablubbabc blablubbabc
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: