Folia icon indicating copy to clipboard operation
Folia copied to clipboard

ArrayIndexOutOfBoundsException due to potential thread-unsafe access in Folia

Open Blurmit opened this issue 5 months ago • 3 comments

Stack trace

[12:44:28] [Region Scheduler Thread #10/ERROR]: Failed to handle packet net.minecraft.network.protocol.game.ServerboundContainerClosePacket@1b2e8eca, suppressing error
java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 10
	at java.base/java.util.ArrayList.add(ArrayList.java:484) ~[?:?]
	at java.base/java.util.ArrayList.add(ArrayList.java:496) ~[?:?]
	at net.minecraft.world.inventory.TransientCraftingContainer.onOpen(TransientCraftingContainer.java:30) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at net.minecraft.world.inventory.AbstractContainerMenu.transferTo(AbstractContainerMenu.java:76) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at org.bukkit.craftbukkit.event.CraftEventFactory.handleInventoryCloseEvent(CraftEventFactory.java:1465) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at net.minecraft.server.network.ServerGamePacketListenerImpl.handleContainerClose(ServerGamePacketListenerImpl.java:2983) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at net.minecraft.server.network.ServerGamePacketListenerImpl.handleContainerClose(ServerGamePacketListenerImpl.java:2975) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at net.minecraft.network.protocol.game.ServerboundContainerClosePacket.handle(ServerboundContainerClosePacket.java:33) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at net.minecraft.network.protocol.game.ServerboundContainerClosePacket.handle(ServerboundContainerClosePacket.java:8) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$1(PacketUtils.java:31) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at net.minecraft.server.level.ServerPlayer.lambda$queuePacketTask$3(ServerPlayer.java:610) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at io.papermc.paper.threadedregions.EntityScheduler.executeTick(EntityScheduler.java:181) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1656) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at io.papermc.paper.threadedregions.TickRegions$ConcreteRegionTickHandle.tickRegion(TickRegions.java:407) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at io.papermc.paper.threadedregions.TickRegionScheduler$RegionScheduleHandle.runTick(TickRegionScheduler.java:418) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at ca.spottedleaf.concurrentutil.scheduler.SchedulerThreadPool$TickThreadRunner.run(SchedulerThreadPool.java:546) ~[concurrentutil-0.0.3.jar:?]
	at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?]

Plugin and Datapack List

[16:18:28 INFO]: ℹ Server Plugins (10):
[16:18:28 INFO]: Paper Plugins (1):
[16:18:28 INFO]:  - CrazyCrates
[16:18:28 INFO]: Bukkit Plugins (9):
[16:18:28 INFO]:  - AnarchyExploitFixes, TradeMe, Vault, ViaBackwards, ViaRewind, ViaVersion, Votifier, WorldEdit, WorldGuard

No datapacks.

Actions to reproduce (if known)

I wasn’t online when it happened, so I don’t know the exact cause. The error suggests the inventory was closed twice concurrently on separate threads, likely causing a race condition.

Folia version

> version
[16:12:38 INFO]: This server is running Folia version 1.21.6-DEV-ver/1.21.6@e4b0ae9 (1970-01-01T00:00:00Z) (Implementing API version 1.21.6-R0.1-SNAPSHOT)
You are running the latest version
Previous version: 1.21.1-DEV-2e7bc07 (MC: 1.21.1)

Other

The user who caused the error said that they were possibly in a trade menu at the time (custom inventory from the TradeMe plugin). Not sure how helpful that is.

Blurmit avatar Jul 27 '25 16:07 Blurmit

You are using an old version

Euphillya avatar Jul 27 '25 18:07 Euphillya

Correct, but this has not been fixed in 1.21.7 or .8, so I feel like this issue remains relevant

Blurmit avatar Jul 27 '25 19:07 Blurmit

I feel that this just goes into the general premise of not sharing local state across contexts, I don't think that there will be much interest in trying to protect this specific backing collection when the entire inventory system is really not designed for concurrent access. This is likely an issue for plugins to resolve

electronicboy avatar Jul 27 '25 20:07 electronicboy