Skip to content

fix(users): never cache a session_version read that a revocation raced; single-flight fills - #863

Merged
antosubash merged 2 commits into
mainfrom
fix/users-session-version-singleflight
Nov 6, 2026
Merged

antosubash merged 2 commits into
mainfrom
fix/users-session-version-singleflight

Conversation

@antosubash

Copy link
Copy Markdown
Owner

Summary

Follow-up to #832 and #839. The users session-revocation cache (users.accounts.session_version_cache) now fills through simple_module_core.singleflight.fill, the epoch-checked fill the tenants and permissions caches already use.

Fixed: a session_version read still in flight when a revocation landed ("sign out everywhere", a password change, a browser logout) was stored after the forget. That put the old counter back, so the revoked sessions passed in that worker until the cache TTL (30 s by default) expired. Every forget, clear and TTL reconfiguration now bumps an epoch, and a read that an epoch change raced is not stored. The read is retried, up to MAX_FILL_ATTEMPTS times.

Changed: concurrent misses for one account share a single read (SingleFlight), so a page that fires several requests on a cold cache makes one DB read.

Unchanged:

  • A database outage still fails open: the check returns True and nothing is cached.
  • TTL 0 still disables caching.

Tests

modules/users/tests/accounts/session_version/test_users_session_version_fill.py:

  • a forget during the read discards it and re-reads;
  • a clear during every read returns the last read uncached;
  • five concurrent misses make one read;
  • a failed read propagates and is not cached.

Verification

  • make lint green.
  • make test-py: 8,147 passed, 47 skipped.
  • make test-js: 898 passed.
  • Codex read-only review: clean. It also exercised the raced fill, retired IDs, TTL 0, fail-open without caching, concurrent fills and three event loops.

https://claude.ai/code/session_01M9neheZZEe3sVpDi2S3zT4

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Deploying simple-module-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1622839
Status: ✅  Deploy successful!
Preview URL: https://052fda7d.simple-module-python.pages.dev
Branch Preview URL: https://fix-users-session-version-si.simple-module-python.pages.dev

View logs

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-11-06T10:15:09.705757Z 1622839 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@antosubash
antosubash merged commit 32f9f28 into main Nov 6, 2026
17 checks passed
@antosubash
antosubash deleted the fix/users-session-version-singleflight branch November 6, 2026 11:59
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