fix: prevent stale async credential clears from overwriting a freshly-set token [IDE-2106]#1353
Open
basti-snyk wants to merge 1 commit into
Open
fix: prevent stale async credential clears from overwriting a freshly-set token [IDE-2106]#1353basti-snyk wants to merge 1 commit into
basti-snyk wants to merge 1 commit into
Conversation
…-set token [IDE-2106]
Test_E2E_AuthenticationMethodChangeClearsIncompatibleToken flaked on
Windows CI: after switching auth method + setting a token in one
didChangeConfiguration, the token sometimes read back empty.
Root cause: on that path applyAuthenticationMethod runs before applyToken.
ConfigureProviders/logout enqueue empty-token clears through the async
OAuth storage bridge (QueueCredentialUpdate("")). The single
credentialUpdateWorker could drain those stale clears AFTER applyToken's
synchronous UpdateCredentials wrote the real token, wiping it.
Fix: a monotonic syncGeneration counter on AuthenticationServiceImpl.
The increment lives in the private updateCredentials, so every
synchronous writer (UpdateCredentials, authenticate, logout) supersedes
earlier-queued async updates; the worker discards any update whose
generation predates the latest synchronous write, giving a strict
happens-before. The worker now holds a.m only for the generation check
and token mutation and releases it before running the
postCredentialUpdateHook, eliminating a reentrancy deadlock hazard.
Adds regression tests for the authenticate, logout, and rapid-rotation
paths plus a worker-hook no-deadlock test.
Produced by an automated flake-fix loop.
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
PR Reviewer Guide 🔍
|
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.
Summary
Test_E2E_AuthenticationMethodChangeClearsIncompatibleToken(Windows CI, IDE-2106), where switching auth method and setting a token in onedidChangeConfigurationsometimes left the token empty.applyAuthenticationMethodruns beforeapplyToken.ConfigureProviders/logoutenqueue empty-token clears through the async OAuth storage bridge (QueueCredentialUpdate("")). The singlecredentialUpdateWorkercould drain those stale clears afterapplyToken's synchronousUpdateCredentialswrote the real token, wiping it.syncGenerationcounter onAuthenticationServiceImpl. The increment lives in the privateupdateCredentials, so every synchronous writer (UpdateCredentials,authenticate,logout) supersedes earlier-queued async updates; the worker discards any update whose generation predates the latest synchronous write — a strict happens-before. The worker now holdsa.monly for the generation check + token mutation and releases it before running thepostCredentialUpdateHook, removing a reentrancy deadlock hazard.Test plan
go test ./infrastructure/authentication/... -racegreenTest_E2E_AuthenticationMethodChangeClearsIncompatibleTokenproven RED before fix, 200/200 GREEN after (-race,-cpu=1,2,4)make test(full unit suite) green at this commitThis fix was produced by an automated flake-fix loop.