gamerx/Backup — Issue #63: Save-all is async, please make it synced
Author: bergerkiller
Created: 2012-01-22 18:53:31+00:00
State: open

In your plugin, you are invoking save-all to 'save' the worlds:
https://github.com/gamerx/Backup/blob/master/src/main/java/net/tgxn/bukkit/backup/threading/PrepareBackup.java#L113

However, since the latest CraftBukkit versions save-all is no longer synchronized. This means that ,after using save-all, it puts all chunks into a queue for saving. While you are copying the worlds over, chunks are (and can) still be saved in the FileIOThread, which can cause IO Exceptions and corrupted saved data.

To fix this, make sure the world is entirely written to file: check if the pending chunk set of the ChunkRegionLoader still contains elements or not.

See also:
The field you need to check using reflection (ChunkRegionLoader class):
https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/ChunkRegionLoader.java#L15

The field you need to obtain using reflection from the ChunkProviderServer class:
https://github.com/Bukkit/CraftBukkit/blob/master/src/main/java/net/minecraft/server/ChunkProviderServer.java#L27

Again, it is VERY important to wait until all chunks are saved by the IO thread. Also, obtain the lock object and wrap a synchronized block around it when checking the list, or it may cause issues:
https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/ChunkRegionLoader.java#L17

Please do fix this, as it can cause broken backups.