Skip to content

Wait for a pending save before loading player data on rejoin - #181

Open
JanTuck wants to merge 1 commit into
SpigotBasics:mainfrom
JanTuck:fix-player-data-rejoin-race
Open

JanTuck wants to merge 1 commit into
SpigotBasics:mainfrom
JanTuck:fix-player-data-rejoin-race

Conversation

@JanTuck

@JanTuck JanTuck commented Oct 14, 2026

Copy link
Copy Markdown

Fixes a race in ModulePlayerDataLoader between a player's quit and a quick rejoin.

Problem

On quit, saveAndForgetAll runs asynchronously: each module saves, then forgets the player's data. If the player rejoins before that finishes:

  1. loadAll on AsyncPlayerPreLoginEvent can read storage before the save has written, so the player gets stale data.
  2. The delayed forgetPlayerData then runs after the new load and removes the freshly loaded data, leaving an online player with none (e.g. basics-homes errors with HomeList for <uuid> doesn't exist).

This affects every module that uses the player data lifecycle (basics-homes, and the new basics-back / basics-god from #168 and #173).

Fix

  • onPlayerQuit keeps the saveAndForgetAll future in pendingSaves until it completes. That future completes only after every module has both saved and forgotten.
  • On login, the load is chained after that player's pending save, if any. A failed save is ignored (handle), so the login still loads.
  • pendingSaves.remove(uuid, future) only removes that exact future, so an older save finishing can't drop a newer one.

Joins without a recent quit are unchanged. The wait counts towards the existing storage.yml join timeout, so a slow save can't hang a login.

Testing

  • ./gradlew :core:build (compile + ktlint + tests) passes on Java 17. Not exercised on a live server.

On quit, modules save and then forget player data asynchronously. A quick rejoin
could load before the save had written (stale data), and the delayed forget could
then drop the freshly loaded data. Logins now wait for that player's pending save.
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