Skip to content

Fix race condition in SoulboundListener Folia task scheduling#1193

Merged
StarWishsama merged 2 commits into
feature/foliafrom
copilot/sub-pr-1059-again
Mar 3, 2026
Merged

Fix race condition in SoulboundListener Folia task scheduling#1193
StarWishsama merged 2 commits into
feature/foliafrom
copilot/sub-pr-1059-again

Conversation

Copilot AI commented Feb 27, 2026

Copy link
Copy Markdown

The containsKeyrunAtEntityLaterput sequence in onRespawn(EntityDeathEvent) was non-atomic, allowing two concurrent death events for the same player to each pass the guard check and schedule duplicate soulbound-return tasks.

Changes

  • returnTasks: HashMapConcurrentHashMap; replaced containsKey + put with computeIfAbsent to atomically guarantee at most one scheduled task per UUID
  • soulbound: HashMapConcurrentHashMap to cover concurrent access between the death handler and respawn handler on Folia
// Before — not atomic; two threads can both pass containsKey and schedule
if (returnTasks.containsKey(p.getUniqueId())) { return; }
WrappedTask task = Slimefun.getPlatformScheduler().runAtEntityLater(p, () -> { ... }, 10L);
returnTasks.put(event.getEntity().getUniqueId(), task);

// After — single atomic check-and-insert
returnTasks.computeIfAbsent(p.getUniqueId(), uuid ->
    Slimefun.getPlatformScheduler().runAtEntityLater(p, () -> { ... }, 10L));

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…o prevent race condition

Co-authored-by: StarWishsama <25561848+StarWishsama@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback from review on previous pull request Fix race condition in SoulboundListener Folia task scheduling Feb 27, 2026
@StarWishsama
StarWishsama marked this pull request as ready for review March 3, 2026 03:21
@StarWishsama
StarWishsama merged commit e708b2e into feature/folia Mar 3, 2026
4 checks passed
@StarWishsama
StarWishsama deleted the copilot/sub-pr-1059-again branch March 3, 2026 03:22
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.

2 participants