Fixes exhaustion when loading large profiles #4127
Merged
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.
Description
Fixes exhaustion when loading large PlayerProfiles due to multiple load calls being made.
If we're already loading the profile, we don't want to spin up a whole new thread and load the profile again/more. This can very easily cause CPU, memory and thread exhaustion if the profile is large
We saw AbstractArmorTask constantly try to get the PlayerProfile (every 10 mc ticks) even though the profile was still being loaded (due to it's very large size). This compounded the issue and ended up killing servers off entirely.
Proposed changes
Add tracking for when we're loading the PlayerProfile from file into memory. If the profile is loading, we will simply return and not try to load it again. This does mean that callbacks for PlayerProfile#get are currently tossed away, this isn't ideal but IMO is acceptable here. It will just mean if someone interacts with a block/item quickly and they have a large profile, instead of the interaction happening after load it will just not happen and they will need to re-interact. This is only for first load so not a big deal but worth calling out.
Related Issues (if applicable)
Fixes #4011
Fixes #4116
Checklist
Nonnull
andNullable
annotations to my methods to indicate their behaviour for null values