Skip to content

Fix race condition in auth manager initialization#62431

Open
kimyoungi99 wants to merge 2 commits intoapache:mainfrom
kimyoungi99:fix/thread-safe-auth-manager-init-v2
Open

Fix race condition in auth manager initialization#62431
kimyoungi99 wants to merge 2 commits intoapache:mainfrom
kimyoungi99:fix/thread-safe-auth-manager-init-v2

Conversation

@kimyoungi99
Copy link
Contributor

@kimyoungi99 kimyoungi99 commented Feb 24, 2026

Closes #61108

This is a follow-up to #62214 (reverted in #62404).

Problem

Concurrent requests to /auth/token cause intermittent 500 errors:

AttributeError: 'AirflowAppBuilder' object has no attribute 'sm'

create_auth_manager() creates a new instance on every call. Under concurrent requests, one thread overwrites _AuthManagerState.instance while another's is still initializing.

Previous approach (#62214) and why it was reverted

The previous fix added purge_cached_app() in get_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 with KeyError: 'AUTH_USER_REGISTRATION'.

This fix

  1. create_auth_manager(): Double-checked locking with isinstance validation — creates the singleton once, replaces it only when the auth manager class changes (e.g. SimpleAuthManagerFabAuthManager).

  2. init_appbuilder.py: Clears security_manager @cached_property when init_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.

@kimyoungi99 kimyoungi99 force-pushed the fix/thread-safe-auth-manager-init-v2 branch from f25b370 to 82796cd Compare February 24, 2026 20:10
@eladkal eladkal added area:core backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch and removed area:providers provider:fab labels Feb 25, 2026
@eladkal eladkal added this to the Airflow 3.1.8 milestone Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API area:core backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Race condition causes "AirflowAppBuilder has no attribute 'sm'" on concurrent auth requests

3 participants