Fix TamableAnimal race condition #426
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With Folia, teleporting a tamed animal, like a wolf, to a player that is now not in the same region, is technically thread-safe because of Folias current patch. However, there is a race condition where if the chunk the tamed animal is trying to teleport to isn't loaded yet, it crashes the server because when it is trying to check if it CAN teleport, it tries to check blocks in that chunk, but if the chunk isn't loaded, it tries to load it. Thus causing a crash since if the target location isn't in the same region, it will kill the server because of a bad access(trying to load chunk outside owning region).
The fix proposed here just checks if the chunk is loaded first, and if it is loaded, then it will proceed. Otherwise, returns false.