mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2318] [Issue]: Concurrent Spotify token refresh clobbers the rotated refresh token, permanently breaking the connection #1143
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1143
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Romuromylus on GitHub (Jun 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2318
Originally assigned to: @Romuromylus on GitHub.
Summary
Severity: Medium — Concurrency / credential corruption. Spotify's Authorization Code + PKCE flow rotates the refresh token on every refresh and invalidates the previous one. Token refresh in
resolve_credentialshas no serializing lock, so when two Spotify commands run concurrently in the ~60s pre-expiry window they each refresh with the same stale refresh token; Spotify hands each a different new token and invalidates the prior. The racingsave_spotify_tokenswrites are last-writer-wins, so the persisted token can be one Spotify already invalidated — permanently breaking the connection until the user manually reconnects.Expected behavior
Concurrent Spotify commands should serialize token refresh: the second caller waits and re-reads the freshly-saved token rather than issuing a second refresh with the now-stale refresh token.
Actual behavior
src-tauri/src/commands/storage/integrations/spotify.rs,resolve_credentials(2547-2633), proactive refresh at 2594-2596:refresh_agent_token(2646-2669) postsgrant_type=refresh_tokenwith no client secret (public-client PKCE), andsave_spotify_tokens(2671-2733) unconditionally overwritesspotifyRefreshTokenEncrypted(2713-2717). The only static lock in the file isSPOTIFY_TRACK_INDEX_CACHE(line 60) — there is no lock around token refresh. Each Spotify op is a separate#[tauri::command] async fn(commands/integrations.rs:spotify_player,spotify_devices,spotify_access_token,spotify_player_play/pause/next/volume), and Tauri runs them concurrently.SpotifyMiniPlayer.tsxpollsplayerQueryanddevicesQueryevery 5s (independentuseQuery, no dedup), so tworesolve_credentialsroutinely overlap.The storage write-lock makes each individual
patchatomic but does NOT serialize the two network refreshes or prevent stale-token reuse.Steps to reproduce
Impact area
Environment
b0e5561dLogs, screenshots, or video
Static source audit; cited to file:line above.
Regression notes
Found via static audit of the refactor branch; not verified against main.
Additional context
Probabilistic trigger (needs the token near expiry while two commands overlap) and recovery is a one-click reconnect, hence medium not high — but it silently corrupts a stored credential. Suggested fix: serialize refresh per agent via a per-agent
tokio::sync::Mutex(e.g.static OnceLock<Mutex<HashMap<agent_id, Arc<Mutex<()>>>>>); after acquiring, re-read settings and skip the network refresh if another task already refreshed (expires_atnow in the future).Template check
Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:
@Romuromylus commented on GitHub (Jun 6, 2026):
Fixed by #2400, merged into
refactor.