mojira.dev
MC-79154

Hoppers occasionally duplicate items

Server duplicates items in hoppers. After a while, all hopper clocks are getting broken, because there is more than one item in it. I managed to duplicate diamond blocks.

Server Console says:

[13:01:44] [Server thread/WARN]: Fetching addPacket for removed entity
[13:01:44] [Server thread/WARN]: Fetching addPacket for removed entity
[13:01:44] [Server thread/WARN]: Fetching addPacket for removed entity
[13:01:44] [Server thread/WARN]: Fetching addPacket for removed entity
[13:01:44] [Server thread/WARN]: Fetching addPacket for removed entity
[13:01:44] [Server thread/WARN]: Fetching addPacket for removed entity
[13:01:44] [Server thread/WARN]: Fetching addPacket for removed entity
[13:02:23] [Server thread/WARN]: Can't keep up! Did the system time change, or is the server overloaded? Running 2144ms behind, skipping 42 tick(s)

Edit: I now caught it happening. A hopper speed up so fast, that even a comparator doesn't work anymore. I'm sure this leads to item duplication.


Code analisys by @unknown can be found in this comment.

Linked issues

Attachments

Comments 18

After having this issue:
Please force a crash by pressing F3 + C for 10 seconds while in-game and attach the crash report ([minecraft/crash-reports/crash-<DATE>-client.txt|http://hopper.minecraft.net/help/finding-minecraft-data-folder]) here.

This is a payed 14/7 Server, I will try my best to catch the issue happening.
Are you sure it is client releated? Also I've found this Bug-Report: (MC-78155) In the comments people say this speed up could cause duplication.

Log of forced crash

I see this bug in chunks charged with redstone and lazychunks.

Martin Bittermann

Can confirm this. We had a lot of hopper pairs facing into each other across chunk borders on or SMP server, in an attempt to create chunk loaders. We had a single item of cobblestone oscillating in each hopper pair. Upon inspection after a few weeks, most hoppers had 2-4 stacks of cobblestone. I first thought those had been left there on accident, when digging the tunnels, but turns out this was the item duplication bug. Then I recreated the setup in our base, with 3 pairs of hoppers, two of them at a chunk border, with different items, one item per pair. All three had about 4-7 items in each hopper, overnight.
I'm not sure whether it has something to do with the server messages "[Server thread/WARN]: Fetching addPacket for removed entity". I had some of these, too, but only 3 that night. One other player was logged into the server at that time.

8 more comments
Timothy Miller

One other thing. I think it may be better to move the "removeAll" code to much earlier. There are things that happen between queueing chunks to unload and deleting the tile entities that may cause other chunks to get reloaded that were just queued. If that happens, we may have the analogous bugs to what is causing the hopper problem.

The way I have it now is to delete the tileentity deletion code from World.updateEntities and move it into its own function in World:

public void removeUnloadedTileEntities()
{   
    if (!this.tileEntitiesToBeRemoved.isEmpty())
    {   
        this.tickableTileEntities.removeAll(this.tileEntitiesToBeRemoved);
        this.loadedTileEntityList.removeAll(this.tileEntitiesToBeRemoved);
        this.tileEntitiesToBeRemoved.clear();
    }
}

Then I insert a call to that RIGHT AFTER WorldServer.tick calls chunkProvider.unloadQueuedChunks, like this:

this.theProfiler.endStartSection("chunkSource");
    this.chunkProvider.unloadQueuedChunks();
    removeUnloadedTileEntities(); // new line

Confirmed in 1.12.1

Timothy Miller

I have not done a full analysis of the code between calling unloadQueuedChunks and doing removeAll. If the tile entities are removed right after being marked for removal as in my previous comment, then this is guaranteed safe with regard to tile entities.

If removeUnloadedTileEntities is called somewhere else, the thing we have to be careful about is with respect to other code in between unloadQueuedChunks and doing the removeAll. One thing in particular is ticking regular entities. Normally, they would not be ticked when unloaded chunks are nearby, but with multiple players, it's really easy to make chunk go directly from entity-processing to being unloaded, and this creates another opportunity for chunks to be unloaded and then reloaded on the same game tick. To be sure, the entity code deletes and ticks already in the right order. I'm just concerned about potential race conditions that haven't been fully ruled out. (Depending on what else is going on, we may want to delete regular entities earlier also!)

I was going to test these ideas, but MC-2025 got in my way. Although there have been fixes proposed earlier, I'm planning on doing a thorough analysis myself just to see if I can corroborate what others have said. Hopefully that will help add confidence to any community-proposed fixes. Either way, until 2025 is fixed, it's going to take some extra work for me to come up with a test case for regular entities and the interaction with loading and unloading, duping on chunk boundaries, MC-119971, etc.

Thanks!

Marking as fixed for now. If something comes up with the entity code, let's create a new issue.

Timothy Miller

Thanks @devs and @mods for getting this fixed!

We can now rely on hopper clocks not breaking, as long as they don't straddle a chunk boundary!!

However, if hopper pairs are put on a chunk boundary, it's still really easy to get them to dupe items, so we may want to think a little bit about whether or not the bug-as-originally-reported is really fixed, given that it's still possible to make hoppers dupe items. One of the causes is fixed by applying the fix attached to MC-79154 (which is a HUGE improvement, so thank you), but another cause isn't. The fix for the chunk boundary case is attached to MC-119971.

Long hopper lines for item delivery may still experience some problems, and pistons pushing blocks across chunk boundaries definitely will. Those are also fixed by the solution attached to MC-119971. In fact, the fix attached to MC-119971 is likely to also fix entity duplication and deletion that sometimes occurs at chunk boundaries. That fix is also being added to carpetmod so that community members can test it further.

Ole

(Unassigned)

Confirmed

Minecraft 1.8.3, Minecraft 1.8.8, Minecraft 15w45a, Minecraft 1.9, Minecraft 1.11.2, Minecraft 1.12, Minecraft 1.12.1 Pre-Release 1, Minecraft 1.12.1

Minecraft 1.12.2 Pre-Release 1

Retrieved