Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WildStacker IllegalStateException #313

Closed
Kryniowesegryderiusz opened this issue May 31, 2024 · 9 comments
Closed

WildStacker IllegalStateException #313

Kryniowesegryderiusz opened this issue May 31, 2024 · 9 comments
Assignees
Labels
done this has been completed

Comments

@Kryniowesegryderiusz
Copy link

Kryniowesegryderiusz commented May 31, 2024

Expected behavior

Level should be counted properly

Observed/Actual behavior

https://github.com/BentoBoxWorld/Level/blob/develop/src/main/java/world/bentobox/level/calculators/IslandLevelCalculator.java#L660 fires IllegalStateException for some locations. That makes finishTask beeing completed only after timeout due to these locations still remaining

Steps/models to reproduce

Thats the hard part. Im not able to reproduce it on my test server, but it happens on huge words with players.

But I'm basically doing /is level or /bsb level commands.

BentoBox version

31.05 19:54:50 [Server] INFO Running PURPUR 1.20.4.
31.05 19:54:50 [Server] INFO (git-Purpur-2152 (MC: 1.20.4))
31.05 19:54:50 [Server] INFO BentoBox version: 2.1.2-SNAPSHOT-b2572
31.05 19:54:50 [Server] INFO Database: MYSQL
31.05 19:54:50 [Server] INFO Loaded Game Worlds:
31.05 19:54:50 [Server] INFO skyblock (SkyBlock): Swiat, Pieklo, End
31.05 19:54:50 [Server] INFO Loaded Addons:
31.05 19:54:50 [Server] INFO Biomes 2.2.0-SNAPSHOT-b258 (ENABLED)
31.05 19:54:50 [Server] INFO Border 4.2.1 (ENABLED)
31.05 19:54:50 [Server] INFO BSkyBlock 1.17.1 (ENABLED)
31.05 19:54:50 [Server] INFO DimensionalTrees 1.7.0 (ENABLED)
31.05 19:54:50 [Server] INFO Level 2.13.0 (ENABLED)
31.05 19:54:50 [Server] INFO Limits 1.20.1 (ENABLED)
31.05 19:54:50 [Server] INFO SkyblockCore 0.5 (ENABLED)
31.05 19:54:50 [Server] INFO SkyIslandUpgrades 0.1 (ENABLED)
31.05 19:54:50 [Server] INFO Warps 1.14.0 (ENABLED)

Plugin list

No response

Other

Error I've managed to get in console is:

31.05 19:05:59 [Server] WARN java.lang.IllegalStateException
31.05 19:05:59 [Server] WARN at java.base/java.util.ArrayList$Itr.remove(ArrayList.java:980)
31.05 19:05:59 [Server] WARN at Level-2.13.0-SNAPSHOT-LOCAL.jar//world.bentobox.level.calculators.IslandLevelCalculator.lambda$handleStackedBlocks$15(IslandLevelCalculator.java:701)
31.05 19:05:59 [Server] WARN at java.base/java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:718)
31.05 19:05:59 [Server] WARN at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
31.05 19:05:59 [Server] WARN at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2147)
31.05 19:05:59 [Server] WARN at org.bukkit.craftbukkit.v1_20_R3.CraftWorld.lambda$getChunkAtAsync$17(CraftWorld.java:2524)
31.05 19:05:59 [Server] WARN at net.minecraft.server.TickTask.run(TickTask.java:18)
31.05 19:05:59 [Server] WARN at net.minecraft.util.thread.IAsyncTaskHandler.d(IAsyncTaskHandler.java:153)
31.05 19:05:59 [Server] WARN at net.minecraft.util.thread.IAsyncTaskHandlerReentrant.d(IAsyncTaskHandlerReentrant.java:24)
31.05 19:05:59 [Server] WARN at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1488)
31.05 19:05:59 [Server] WARN at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:194)
31.05 19:05:59 [Server] WARN at net.minecraft.util.thread.IAsyncTaskHandler.x(IAsyncTaskHandler.java:126)
31.05 19:05:59 [Server] WARN at net.minecraft.server.MinecraftServer.bl(MinecraftServer.java:1465)
31.05 19:05:59 [Server] WARN at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:1388)
31.05 19:05:59 [Server] WARN at net.minecraft.util.thread.IAsyncTaskHandler.c(IAsyncTaskHandler.java:136)
31.05 19:05:59 [Server] WARN at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:1539)
31.05 19:05:59 [Server] WARN at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1236)
31.05 19:05:59 [Server] WARN at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:323)
31.05 19:05:59 [Server] WARN at java.base/java.lang.Thread.run(Thread.java:833)

Lines numbers may differ due to some debug messages added

My latest debug code looks like that:

    private void handleStackedBlocks() {
    	
	    Bukkit.broadcastMessage("handleStackedBlocks");
	    	
		try {
			// Deal with any stacked blocks
			Iterator<Location> it = stackedBlocks.iterator();
			while (it.hasNext()) {
			    Location v = it.next();
			    System.out.println("it.next() " + v);
			    Util.getChunkAtAsync(v).thenAccept(c -> {
					try {
						Block stackedBlock = v.getBlock();
						boolean belowSeaLevel = seaHeight > 0 && v.getBlockY() <= seaHeight;
						if (WildStackerAPI.getWildStacker().getSystemManager().isStackedBarrel(stackedBlock)) {
						    StackedBarrel barrel = WildStackerAPI.getStackedBarrel(stackedBlock);
						    int barrelAmt = WildStackerAPI.getBarrelAmount(stackedBlock);
						    for (int _x = 0; _x < barrelAmt; _x++) {
							checkBlock(barrel.getType(), belowSeaLevel);
						    }
						} else if (WildStackerAPI.getWildStacker().getSystemManager().isStackedSpawner(stackedBlock)) {
						    int spawnerAmt = WildStackerAPI.getSpawnersAmount((CreatureSpawner) stackedBlock.getState());
						    for (int _x = 0; _x < spawnerAmt; _x++) {
							checkBlock(stackedBlock.getType(), belowSeaLevel);
						    }
						}
						it.remove();
						System.out.println("it.remove() " + v);
					} catch (Exception e) {
						System.out.println(e + " " + v);
					}
			    });
			}
			
			Bukkit.broadcastMessage("stackedBlocks size: " + stackedBlocks.size());
			Bukkit.broadcastMessage("handleStackedBlocksEnded");
		} catch (Exception e) {
			Bukkit.broadcastMessage(e.getMessage());
			e.printStackTrace();
		}
    }
    ```
@Kryniowesegryderiusz
Copy link
Author

This was the output of that particular debug
log.txt

@tastybento
Copy link
Member

Pretty sure I found the issue. It's due to async actions and should be fairly straightforward to fix but will be hard to verify.

@Kryniowesegryderiusz
Copy link
Author

I have the server, where its really easily replicable. I have two weeks between seasons right now, so as there are no players online I'm open for testing

@tastybento tastybento self-assigned this May 31, 2024
@tastybento tastybento added the in progress this is being worked on label May 31, 2024
@tastybento
Copy link
Member

Okay, I just merged in the new code. I still need to test on my end too, but in the interests of having help here, try it. It'll be on ci.bentobox.world soon.

@tastybento
Copy link
Member

#314

@tastybento tastybento added done this has been completed and removed in progress this is being worked on labels May 31, 2024
@Kryniowesegryderiusz
Copy link
Author

Kryniowesegryderiusz commented May 31, 2024

The problem still persists, but now I cannot get any stacktrace. I'm working on it.

Somehow not all locations are beeing added to toRemove

@Kryniowesegryderiusz
Copy link
Author

I think some locations are beeing added after removeAll method.

Adding is when toRemove is increased

Removing 1314 stacked blocks from 1324 is when removeAll is beeing executed

stackedBlocks.size(): 10toRemove.size(): 0 is inside finishTask

[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=16.0,y=154.0,z=293.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1303
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=16.0,y=146.0,z=295.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1304
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=16.0,y=150.0,z=295.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1305
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=16.0,y=146.0,z=297.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1306
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=16.0,y=150.0,z=297.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1307
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=16.0,y=154.0,z=297.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1308
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=16.0,y=146.0,z=299.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1309
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=16.0,y=150.0,z=299.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1310
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=16.0,y=154.0,z=299.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1311
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=16.0,y=150.0,z=301.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1312
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=17.0,y=150.0,z=294.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1313
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=17.0,y=150.0,z=296.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1314
[00:10:06] [Server thread/INFO]: Removing 1314 stacked blocks from 1324
[00:10:06] [Server thread/INFO]: stackedBlocks.size(): 10toRemove.size(): 0
[00:10:06] [Server thread/INFO]: stackedBlocks.size(): 10toRemove.size(): 0
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=-37.0,y=265.0,z=298.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1315
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=-35.0,y=256.0,z=305.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1316
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=-32.0,y=267.0,z=295.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1317
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=-12.0,y=146.0,z=287.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1318
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=-15.0,y=150.0,z=296.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1319
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=-12.0,y=-2.0,z=304.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1320
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=0.0,y=142.0,z=281.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1321
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=0.0,y=138.0,z=289.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1322
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=0.0,y=138.0,z=305.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1323
[00:10:06] [Server thread/INFO]: Adding Location{world=CraftWorld{name=skyblock},x=16.0,y=146.0,z=291.0,pitch=0.0,yaw=0.0} to toRemove. New size: 1324

@tastybento tastybento added Under Investigation and removed done this has been completed labels Jun 1, 2024
tastybento added a commit that referenced this issue Jun 1, 2024
This uses CompleteableFutures instead of a recurring Bukkit task to
check if collections have been removed. This is a much more reliable way
to do it because it will complete when all the tasks are done and not
before.
@tastybento tastybento added done this has been completed and removed Under Investigation labels Jun 1, 2024
@tastybento
Copy link
Member

Reworked the whole approach. Please try it.

@Kryniowesegryderiusz
Copy link
Author

Yup, just wanted you to know it works. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
done this has been completed
Projects
None yet
Development

No branches or pull requests

2 participants