fix(renewTokens): prevent infinite loop on renew token flow #1581
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.
Users who leave the application running in the background and subsequently lose VPN connectivity are generating excessive "Failed to fetch" errors in our observability logs. This issue arises because the application does not transition to the "Session Lost" state as expected, due to a flaw in the synchroniseTokensAsync function. Properly handling this scenario by moving affected sessions to the "Session Lost" state would mitigate unnecessary error logging.
A picture tells a thousand words
Before this PR
The synchroniseTokensAsync function in renewTokens.ts could enter an infinite loop when an error occurred during token renewal, as recursive calls to itself were made without a proper break incrementing the "index" variable when the window document is hidden.
After this PR
The implementation now prevents infinite recursion in synchroniseTokensAsync by breaking the call chain. This ensures that errors during token renewal do not cause stack overflow, improving reliability and browser stability.