Skip to content

Fix Desktop.Auth login key race under concurrent first access#77

Merged
dominicletz merged 3 commits into
mainfrom
fix/auth-key-race
Jul 22, 2026
Merged

Fix Desktop.Auth login key race under concurrent first access#77
dominicletz merged 3 commits into
mainfrom
fix/auth-key-race

Conversation

@dominicletz

Copy link
Copy Markdown
Collaborator

Summary

  • Fixes a race in Desktop.Auth.key/0: non-atomic :persistent_term check-then-set could mint two different keys when Window.prepare_url/1 and the Auth plug initialize concurrently under load.
  • That left the webview with a stale ?k= and a blank "Unauthorized" page (seen in diodechain/ddrive#4106).
  • Elect a single winner with ETS insert_new/2, keep :persistent_term as the fast read path, and keep set_key/1 in sync with both stores.

Test plan

  • NO_WX=1 mix test test/auth_test.exs test/window_test.exs
  • Confirm concurrent login_key/0 callers always agree after a cold start
  • Smoke: open a desktop app once under load and confirm no blank Unauthorized page on first focus

Made with Cursor

Concurrent first access from prepare_url and the Auth plug could mint
different keys via non-atomic persistent_term check-then-set. Elect a
single winner with ETS insert_new while keeping persistent_term as the
fast read path.

Co-authored-by: Cursor <cursoragent@cursor.com>
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

dominicletz and others added 2 commits July 23, 2026 07:37
Drop the redundant ETS pre-lookup before insert_new, trim defensive
test reset code, and keep persistent_term as the hot-path cache.

Co-authored-by: Cursor <cursoragent@cursor.com>
Mirror the ddrive diagnostics: path, whether a k was present, and peer,
so stale-key Unauthorized pages are visible in logs.

Co-authored-by: Cursor <cursoragent@cursor.com>
@dominicletz
dominicletz merged commit 75f91f4 into main Jul 22, 2026
2 checks passed
@dominicletz
dominicletz deleted the fix/auth-key-race branch July 22, 2026 23:50
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