Skip to content

fix(player): detect stale player data writes across servers - #281

Merged
TheMeinerLP merged 1 commit into
mainfrom
fix/player-stale-writes
Nov 23, 2026
Merged

TheMeinerLP merged 1 commit into
mainfrom
fix/player-stale-writes

Conversation

@TheMeinerLP

Copy link
Copy Markdown
Contributor

Summary

With player data now cached on the server the player is on (#279), one gap remained: when a player switches between two servers running StarDust, Velocity connects them to the new server before disconnecting them from the old one. The new server can load the player before the old server's last change has reached the database, and an administrator can change a player who is online somewhere else. In both cases an outdated copy could later overwrite newer data without anyone noticing.

Every player copy now remembers the database version it was loaded with. A write is only accepted while that version is still the stored one; otherwise it is rejected, the server reloads the current data from the database and logs a warning with both versions. A player who is inserted twice at the same moment keeps the existing row instead of failing. No message broker or new service is needed: the version column already exists, and a player is only ever written by the server they are on.

Implements the OpenSpec change guard-player-data-handoff (#278).

Notes

  • Tests: ./gradlew cleanTest test passes; 6 new database tests against an in-memory H2 database (stale write rejected, matching write advances the version, consecutive writes of the same copy succeed, duplicate insert keeps the stored row) and a cache test for the reload on conflict.
  • Not covered by tests: the narrow race where two servers flush the same row at the same instant (mapped from Hibernate's optimistic lock exception).
  • No configuration or schema change.

A player can be written from a stale copy after a server switch or an
admin edit, which silently overwrote newer data. The player model now
carries the entity version, updates are only accepted while the stored
version matches, and a conflict reloads the database state into the
cache instead of writing.
@TheMeinerLP
TheMeinerLP requested a review from a team as a code owner November 23, 2026 20:54
@github-actions

Copy link
Copy Markdown
Contributor

Test results

 36 files   36 suites   21s ⏱️
 67 tests  40 ✅ 27 💤 0 ❌
201 runs  120 ✅ 81 💤 0 ❌

Results for commit 52060e3.

@TheMeinerLP
TheMeinerLP merged commit 037987c into main Nov 23, 2026
13 checks passed
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