feat(): Critical Stability & Reliability Fixes - #12
Open
Arielpetit wants to merge 1 commit into
Open
Conversation
Author
|
@gabconcepcionph @alzithetrivialmind @baairon can you please review this PR? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description: Critical Stability & Reliability Fixes
Overview
This PR resolves three critical issues affecting application reliability, performance, and data consistency. The changes eliminate unnecessary Spotify token refreshes, prevent MPV connection race conditions, and ensure accurate version tracking across library and playback history mutations.
Issues Fixed
1. Fixed Spotify Token Cache Invalidation
Problem
The Spotify token cache validation logic refreshed access tokens 30 seconds before their actual expiration, resulting in unnecessary authentication requests.
Root Cause
The cache validation used a buffered expiration check:
Although the buffer was intended as a safety margin, it caused valid tokens to be discarded prematurely.
Solution
Updated the validation logic to check only whether the token has actually expired:
Behavior Change
Before
After
Impact
2. Fixed MPV Connection Reset Race Condition
Problem
A race condition existed between
ensureStarted()andresetConnection(), allowing the connection state to become inconsistent during startup.Root Cause
While
ensureStarted()was establishing a connection,resetConnection()could execute simultaneously and clear the activereadypromise.This resulted in startup failures and unstable MPV connections.
Solution
Added a dedicated
resettingflag to synchronize connection resets.The implementation now:
Behavior Change
Before
After
Impact
3. Fixed Library Index Version Tracking
Problem
Version tracking across the Library and PlayHistory stores could become stale after certain mutations.
Root Cause
The version counter depended on
notify()being called, but not every mutation path triggered it.As a result,
getVersion()could return outdated values after some operations.Solution
Moved version updates directly into every mutation method.
Updated methods include:
Library
upsert()upsertMany()remove()removeMany()clear()PlayHistory
record()retain()Behavior Change
Before
After
Impact
Files Changed
src/sources/spotify/token.tsChanges
Why
src/player/mpv.tsChanges
resettingsynchronization flagWhy
src/library/library.tsChanges
Why
src/player/history.tsChanges
Why
Verification
Impact