Fix race condition in auth manager initialization#62431
Open
kimyoungi99 wants to merge 2 commits intoapache:mainfrom
Open
Fix race condition in auth manager initialization#62431kimyoungi99 wants to merge 2 commits intoapache:mainfrom
kimyoungi99 wants to merge 2 commits intoapache:mainfrom
Conversation
f25b370 to
82796cd
Compare
vincbeck
approved these changes
Feb 25, 2026
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.
Closes #61108
This is a follow-up to #62214 (reverted in #62404).
Problem
Concurrent requests to
/auth/tokencause intermittent 500 errors:create_auth_manager()creates a new instance on every call. Under concurrent requests, one thread overwrites_AuthManagerState.instancewhile another's is still initializing.Previous approach (#62214) and why it was reverted
The previous fix added
purge_cached_app()inget_application_builder(), but that function is called at runtime by FAB FastAPI routes (login, user/role management). Clearing the singleton on every call broke subsequent core API requests withKeyError: 'AUTH_USER_REGISTRATION'.This fix
create_auth_manager(): Double-checked locking withisinstancevalidation — creates the singleton once, replaces it only when the auth manager class changes (e.g.SimpleAuthManager→FabAuthManager).init_appbuilder.py: Clearssecurity_manager@cached_propertywheninit_app()is called with a new Flask app, so_init_config()runs against the current app context.No changes to
get_application_builder()or test fixtures.Testing
Added
test_create_auth_manager_thread_safety— verifies singleton behavior under 10 concurrent threads.