Skip to content

fix(datastore): Don't let a save cancel the session close - #872

Open
oiisin wants to merge 1 commit into
Quenty:mainfrom
oiisin:users/oiisin/datastore-close-save-race
Open

oiisin wants to merge 1 commit into
Quenty:mainfrom
oiisin:users/oiisin/datastore-close-save-race

Conversation

@oiisin

@oiisin oiisin commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

DataStore._doDataSync replaces _saveMaid on every sync, so each sync cancels the one in flight. If anything calls Save() (the autosave loop, or a caller saving after a purchase) while SaveAndCloseSession() is writing:

  1. the Save replaces the close's maid, so the close is cancelled;
  2. PlayerDataStoreManager's removal sees the close fail and destroys the DataStore;
  3. destroying it cancels the Save too.

Neither writes, and the session lock stays until another server takes it over (the player's next join waits on the lock retries).

While a close is in flight, _syncData now:

  • returns the same promise for another close;
  • cancels any other sync with an empty rejection (like a maid cancel, so it isn't reported as uncaught), both up front and when a sync that started earlier reaches the write after the close began, including the reload path with nothing staged, which would otherwise take the lock again.

A caller such as a receipt handler therefore sees its save fail (and can answer NotProcessedYet) instead of a success that never wrote. Once the close settles, syncs work as before.

Tests in DataStore.GracefulClose.spec.lua: a save during the close doesn't cancel it (fails without this change), a second close shares the first, and saving works again after the close.

Each sync replaces the one in flight. A Save (an autosave, or a caller
saving after a purchase) made while SaveAndCloseSession was writing
cancelled the close; the close then failed, the DataStore was torn
down, which cancelled that save too, so neither wrote and the session
lock stayed until another server took it over.

While a close is in flight, another close now shares it and any other
sync is cancelled (an empty rejection, like a maid cancel) instead of
replacing it, so a caller such as a receipt handler sees the save fail
rather than a success that never wrote. Once the close settles, syncs
work as before.
@oiisin
oiisin deployed to integration November 25, 2026 16:20 — with GitHub Actions Active
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Deploy Results

ℹ️ No changed packages with deploy targets were discovered for this PR. · View logs

Test Results

Package Status Try it
@quenty/datastore ✅ Passed (397/397) (19.3s) Open | Play
@quenty/chatproviderservice ✅ Passed (9/9) (1.5s) Open | Play
@quenty/saveslot ✅ Passed (249/249) (5.3s) Open | Play
@quenty/secrets ✅ Passed (2/2) (1.3s) Open | Play
@quenty/settings ✅ Passed (14/14) (1.5s) Open | Play
@quenty/settings-inputkeymap ✅ Passed (1/1) (1.5s) Open | Play

6 packages tested, 6 passed, 0 failed in 37.5s · View logs

This branch was successfully deployed

1 active deployment
integration — 8290a8ab Deployed Nov 25, 2026 by oiisin via integration-build #848
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