RonanPlugins / BetterRTP

Official wiki of the BetterRTP plugin!
https://www.spigotmc.org/resources/36081/
MIT License
112 stars 85 forks source link

Chunk load server crash 2.13.3 #40

Closed radiant-ai closed 4 years ago

radiant-ai commented 4 years ago

Plugin Version: 2.11.3

Describe The Bug: Player executes /rtp, server crashes

How To Reproduce: Execute /rtp This happended only once on prod server and I could not reproduce this on a testing one, I would not try to use it again on prod though. Rolled back to 2.11.0.

Expected Behavior: No crashes

Screenshots/Error Log: https://pastebin.com/Gw1E3i0J

Additional Context: Server does not have a pregenerated world

SuperRonanCraft commented 4 years ago

I haven't been able to replicate this issue since 2.11.2. If you like, I have a beta build of removing the thread sleeping code for a prettier solution. If you like, feel free to download it here: https://github.com/SuperRonanCraft/BetterRTP/releases/tag/2.12.0 and tell me if it works for you ;)

radiant-ai commented 4 years ago

Ok, I will try it and I will get back to you if I have any problems in the next 24 hours. Thank you!

A248 commented 4 years ago

This is likely caused by BetterRTP doing a busy-spin while waiting for chunks to load. Although this is done on another thread, it still means the thread has to perform tons of useless operations every second until the destination chunks have been loaded. Depending on how long it takes chunks to load this small loop might repeat thousands or millions of times. You can see here:

https://github.com/SuperRonanCraft/BetterRTP/blob/master/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPTeleport.java#L75

The solution to this is to take proper advantage of CompletableFutures and restructure the code to run in a callback once all futures are done. This can be accomplished with CompletableFuture.allOf, for example this pseudo-code:

List<CompletableFuture<Chunk>> asyncChunks;
CompletableFuture.allOf(asyncChunks.toArray(new CompletableFuture[] {})).thenRun(() -> {
  // code continues here
});
SuperRonanCraft commented 4 years ago

Thats actually fairly helpful. I will implement that right away and get this ready for a release soon!