Problem with async saves

I’ve created a plugin that pregenerates chunks. I’m loading chunks asynchronous for the generation on paper.
In some cases the server runs into a problem with saving the world. The stacktrace is:

    [07:06:10] [Server thread/FATAL]: Failed to prepare async save, attempting synchronous save
java.lang.ArrayIndexOutOfBoundsException: 163
	at it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap.get(Long2ObjectOpenHashMap.java:348) ~[patched_1.14.4.jar:git-Paper-192]
	at net.minecraft.server.v1_14_R1.LightEngineStorage.h(SourceFile:77) ~[patched_1.14.4.jar:git-Paper-192]
	at net.minecraft.server.v1_14_R1.LightEngineLayer.a(SourceFile:215) ~[patched_1.14.4.jar:git-Paper-192]
	at net.minecraft.server.v1_14_R1.ChunkRegionLoader.getAsyncSaveData(ChunkRegionLoader.java:310) ~[patched_1.14.4.jar:git-Paper-192]
	at net.minecraft.server.v1_14_R1.PlayerChunkMap.asyncSave(PlayerChunkMap.java:490) ~[patched_1.14.4.jar:git-Paper-192]
	at net.minecraft.server.v1_14_R1.PlayerChunkMap.lambda$a$11(PlayerChunkMap.java:522) ~[patched_1.14.4.jar:git-Paper-192]
	at java.util.concurrent.CompletableFuture.uniAccept(Unknown Source) ~[?:1.8.0_221]
	at java.util.concurrent.CompletableFuture$UniAccept.tryFire(Unknown Source) ~[?:1.8.0_221]
	at java.util.concurrent.CompletableFuture$Completion.run(Unknown Source) ~[?:1.8.0_221]
	at net.minecraft.server.v1_14_R1.PlayerChunkMap.b(PlayerChunkMap.java:442) ~[patched_1.14.4.jar:git-Paper-192]
	at net.minecraft.server.v1_14_R1.PlayerChunkMap.unloadChunks(PlayerChunkMap.java:405) ~[patched_1.14.4.jar:git-Paper-192]
	at net.minecraft.server.v1_14_R1.ChunkProviderServer.tick(ChunkProviderServer.java:533) ~[patched_1.14.4.jar:git-Paper-192]
	at net.minecraft.server.v1_14_R1.WorldServer.doTick(WorldServer.java:348) ~[patched_1.14.4.jar:git-Paper-192]
	at net.minecraft.server.v1_14_R1.MinecraftServer.b(MinecraftServer.java:1208) ~[patched_1.14.4.jar:git-Paper-192]
	at net.minecraft.server.v1_14_R1.DedicatedServer.b(DedicatedServer.java:417) ~[patched_1.14.4.jar:git-Paper-192]
	at net.minecraft.server.v1_14_R1.MinecraftServer.a(MinecraftServer.java:1075) ~[patched_1.14.4.jar:git-Paper-192]
	at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:919) ~[patched_1.14.4.jar:git-Paper-192]
	at java.lang.Thread.run(Unknown Source) [?:1.8.0_221]

I tried to fix this issue by canceling or unloading the requested chunks when the world save event is triggered but that did not work.
Is there a way to find out when the world save starts and when it finished so that I can pause the generation process then? Or is this issue even related to my chunk loading requests?

Vanilla issue, paper will attempt the save again and it should be fine, just mojang and concurrency… Paper also saves chunks incrementally, the event is only fired on a full save, otherwise plugins using the save event to save their own stuff end up killing the server performance

1 Like