fix: post auth hook locking#1214
fix: post auth hook locking#1214ShawkyZ wants to merge 6 commits intorefactor/IDE-1786_folder-config-refactoringfrom
Conversation
✅ 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. |
| a.notifDedup.Unlock() | ||
| } | ||
|
|
||
| if a.postCredentialUpdateHook != nil && newToken != "" { |
There was a problem hiding this comment.
why did you remove it?
There was a problem hiding this comment.
this was added by a previous PR and wasn't necessary since we have the recovery on a global level.
| a.previousAuthCtxCancelFunc() | ||
| a.m.Unlock() | ||
|
|
||
| if a.postCredentialUpdateHook != nil && token != "" && err == nil { |
There was a problem hiding this comment.
why is this now extracted?
There was a problem hiding this comment.
don't want the post hook to be inside the mutex lock, since post hook will trigger a bunch of network calls for fetching FFs. This will affect other calls like IsAuthenticated
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
PR Reviewer Guide 🔍
|
Description
Fix: move postCredentialUpdateHook execution outside the auth lock
The
postCredentialUpdateHook(used to populate feature flags after login) was running insideupdateCredentials, which is called fromauthenticate()whilea.m.Lock()is held. The hook makes HTTP calls to fetch feature flags and SAST settings for every workspace folder. This means:IsAuthenticated()callers (which needRLock) were blockedFix: Remove the hook call from
updateCredentialsand move it toAuthenticate(), where it runs after the lock is released. The hook is still injectable from outside viaSetPostCredentialUpdateHook— the only change is when it executes relative to the lock.Before:
After:
The test is updated to verify the hook runs outside the lock by calling
IsAuthenticated()from within the hook — which would deadlock under the old code.Checklist
make generate)make lint-fix)