mojira.dev
MC-148494

Summoned entities in "ticking" chunks do not despawn, causing resource leak

It is possible to force the generation of persistent entities by summoning them into "ticking" chunks. These entities will not despawn on their own.

This can be seen by summoning entities at the location of other entities within "ticking" chunks. Such entities will persist in memory and can accumulate. This can eventually cause lag and possible crashes if the command is invoked repeatedly because the number of entities grows exponentially.

To reproduce:
1. Create a superflat world.
2. Set the time to eternal night so hostile mobs spawn.
3. Move about 4 chunks from spawn in each direction and return to spawn.
4. Run the following command: `/execute at @e[type=!player] run summon minecraft:evoker_fangs`
5. Run the following command: `/kill @e[type=minecraft:evoker_fangs]` - this sometimes removes evoker fangs, proving they are not removed automatically. Expected outcome for kill command: "no entity was found".

To see the leak, run step 4 several times.

Examples demonstrating exponential growth:

  • running step 4 once before killing the evoker_fangs entities removed 6 entities

  • running step 4 twice removed 18 entities

  • running step 4 10 times removed 6138 entities

  • running step 4 14 times removed 98298 entities and the lag was noticeable

Attachments

Comments 8

The 6 evoker fangs in the first step are breeding with a clear arithmetic progression. At each step, the number of evoker fangs doubles and then 6 more are added. The sequence seen is 6, 18, 42 (all confirmed by test), 90, 186, 378, 762, 1530, 3066 (all inferred), 6138 (confirmed), 12282, 24570, 49146 (all inferred) and 98298 (confirmed). This suggests that evoker fangs that persist in the world are counted as entities when spawning more evoker fangs, which in turn will not be removed.

The arithmetic progression seen here may not occur in different worlds. The world I used was a superflat world with a granite top layer and no structures present (animals did not spawn but hostile mobs did).

Attached is a world save that demonstrates the issue. The redstone machine will spawn 2 persistent evoker fangs per cycle. Disabling the failsafe will cause them to accumulate exponentially.

Attached is a debug report created from the attached world save. Evoker fangs were summoned (with command "/execute at @e[type=!player] run summon minecraft:evoker_fangs") and then the report was created.

Debug report:

[media]

Two evoker fangs still exist in memory. Both of them are located at the same coordinates as two Endermen. These Endermen are located about 150 blocks from the player. If more evoker fangs are summoned, additional evoker fangs will appear at this location.

EDIT: These Endermen are located in "ticking" chunks (not "entity ticking" chunks). An issue with the processing of lazy chunks, perhaps?

Can you please check if that still applies to recent releases. 1.14.4 or 1.15-pre1?

Affects 1.15 prerelease 2. To ensure the bug can be reproduced, I dropped items in a line that passed through lazy chunks, returned to spawn and summoned the evoker fangs.

Can confirm in 1.17.1.

This is much more noticeable in 21w38a with the addition of simulated distance if you bring it down to 2 chunks you can easily see the actual problem.
There are a few ways to fix this issue, either you just unload the entity once it's no longer in entity processing chunks which you can't really do anymore since mojang added simulation distance.
Or you remove them from the server-side while not informing the client-side so that the client still sees the entities that were near it, without wasting performance or memory. Although the client will still have a slight issue with it, but the server no longer will

In 1.18.1 and 22w03a.

bdm68

(Unassigned)

Confirmed

Entities, Performance

Minecraft 1.14 Pre-Release 3, Minecraft 1.14.2, 1.15 Pre-Release 2, 1.17.1, 21w38a, 1.18.1, 22w03a, 1.20.6, 24w21b

Retrieved