Skip to content

fix: don't write last-played history after the device token is revoked - #1187

Merged
rowkav09 merged 1 commit into
mainfrom
fix/last-history-revoke-race
Oct 11, 2026
Merged

rowkav09 merged 1 commit into
mainfrom
fix/last-history-revoke-race

Conversation

@rowkav09

Copy link
Copy Markdown
Member

After an ingest was accepted, recordLastPlay wrote the last-played history with a plain SET. If the device token was revoked in between, the history entry could still be written afterwards.

The write now goes through a small Redis EVAL that checks the token key and writes the history key as one atomic action. If the token is gone, it writes nothing. Retention, ordering, record contents and TTL are unchanged, and a failed history write still doesn't fail an accepted ingest.

Limits: I only tested this against the in-memory Redis emulator. The new Lua script hasn't run against a real Redis or Upstash service; I checked its syntax and atomicity by reading it, and it uses the same EVAL pattern as the existing scripts. The race test uses deferred barriers instead of timers. Without the source change 1 of the 2 new tests fails; with it they pass, and the hosted tests are 212/212 locally. The syntax check and build are clean.

recordLastPlay wrote the last-played history with a plain SET after the
ingest was accepted, so a token revoked in between could still get a
history entry. The write now goes through a small Redis EVAL that checks
the token key and writes the history key as one atomic action; if the
token is gone it writes nothing. Retention, ordering, record contents and
TTL are unchanged, and a failed history write still doesn't fail an
accepted ingest.

Tested against the in-memory Redis emulator only. The new Lua script has
not run against a real Redis or Upstash service; I checked its syntax and
atomicity by reading it, and it follows the same EVAL pattern as the
existing scripts. The race test uses deferred barriers rather than
timers. Without the source change 1 of the 2 new tests fails; with it
they pass.
@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@rowkav09
rowkav09 merged commit f5e1e70 into main Oct 11, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant