Skip to content

Make XP formula caches safe for concurrent access - #5348

Open
cyrne1-7208 wants to merge 1 commit into
mcMMO-Dev:masterfrom
cyrne1-7208:fix/folia-xp-cache-concurrency
Open

cyrne1-7208 wants to merge 1 commit into
mcMMO-Dev:masterfrom
cyrne1-7208:fix/folia-xp-cache-concurrency

Conversation

@cyrne1-7208

@cyrne1-7208 cyrne1-7208 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

FormulaManager fills its four XP requirement caches lazily with computeIfAbsent on plain HashMaps. On Folia, players level up on different region threads at the same time, and on any platform placeholders such as %mcmmo_xp_needed_<skill>% can be requested off the main thread. Concurrent writes can corrupt a HashMap or make computeIfAbsent throw ConcurrentModificationException.

Changes

  • Declare the caches as final ConcurrentMaps backed by ConcurrentHashMap, and remove initExperienceNeededMaps().

No test is added. The XP math reads the mcMMO and ExperienceConfig statics, and Mockito static mocks only apply on the thread that created them, so a test with several threads would not run against the mocks.

Testing

  • mvn test: all tests pass.

@cyrne1-7208

Copy link
Copy Markdown
Contributor Author

I forgot to add comments to the test code ( ; ; )

@cyrne1-7208
cyrne1-7208 force-pushed the fix/folia-xp-cache-concurrency branch from 24c446f to 3b1123e Compare September 23, 2026 09:17
@cyrne1-7208
cyrne1-7208 marked this pull request as draft October 8, 2026 03:52
FormulaManager fills its XP requirement caches lazily with
computeIfAbsent on plain HashMaps. On Folia, players level up on
several region threads at once, and placeholders such as
%mcmmo_xp_needed_<skill>% can be requested off the main thread on any
platform, so concurrent writes could corrupt a map or make
computeIfAbsent throw ConcurrentModificationException.

The caches are now final ConcurrentMaps backed by ConcurrentHashMap.

Signed-off-by: Cyrne1_7208 <127477265+cyrne1-7208@users.noreply.github.com>
@cyrne1-7208
cyrne1-7208 force-pushed the fix/folia-xp-cache-concurrency branch from 3b1123e to eb9c0ff Compare October 8, 2026 05:19
@cyrne1-7208 cyrne1-7208 changed the title Make XP formula caches safe for concurrent Folia region access Make XP formula caches safe for concurrent access Oct 8, 2026
@cyrne1-7208
cyrne1-7208 marked this pull request as ready for review October 8, 2026 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant