kimyoungi99 opened a new issue, #61108:
URL: https://github.com/apache/airflow/issues/61108
### Apache Airflow Provider(s)
fab
### Versions of Apache Airflow Providers
apache-airflow-providers-fab==3.1.1
full-list
```
apache-airflow-providers-amazon==9.19.0
apache-airflow-providers-celery==3.15.0
apache-airflow-providers-cncf-kubernetes==10.12.0
apache-airflow-providers-common-compat==1.11.0
apache-airflow-providers-common-io==1.7.0
apache-airflow-providers-common-messaging==2.0.1
apache-airflow-providers-common-sql==1.30.2
apache-airflow-providers-docker==4.5.1
apache-airflow-providers-elasticsearch==6.4.2
apache-airflow-providers-fab==3.1.1
apache-airflow-providers-ftp==3.14.0
apache-airflow-providers-git==0.2.0
apache-airflow-providers-google==19.3.0
apache-airflow-providers-grpc==3.9.1
apache-airflow-providers-hashicorp==4.4.1
apache-airflow-providers-http==5.6.2
apache-airflow-providers-microsoft-azure==12.10.1
apache-airflow-providers-mysql==6.4.0
apache-airflow-providers-odbc==4.11.0
apache-airflow-providers-openlineage==2.9.2
apache-airflow-providers-postgres==6.5.1
apache-airflow-providers-redis==4.4.1
apache-airflow-providers-sendgrid==4.2.0
apache-airflow-providers-sftp==5.5.1
apache-airflow-providers-slack==9.6.1
apache-airflow-providers-smtp==2.4.1
apache-airflow-providers-snowflake==6.8.1
apache-airflow-providers-ssh==4.2.1
apache-airflow-providers-standard==1.10.2
```
### Apache Airflow version
3.1.6
### Operating System
Debian GNU/Linux 12 (bookworm)
### Deployment
Official Apache Airflow Helm Chart
### Deployment details
_No response_
### What happened
Hi, apologies if this is a duplicate or if I've misunderstood the code - I
searched but couldn't find an existing issue.
When sending concurrent requests to `/auth/token`, intermittent 500 errors
occur with:
```
AttributeError: 'AirflowAppBuilder' object has no attribute 'sm'
File ".../airflow/providers/fab/www/extensions/init_appbuilder.py", line
548, in _add_permission
if hasattr(self.sm, "add_permissions_view"):
```
In my case, this is easily reproducible - even just 2 concurrent requests
can trigger the error.
**Suspected cause:**
It appears that `create_auth_manager()` in `api_fastapi/app.py` creates a
new instance on every call without checking for an existing one, which may
cause race conditions when multiple requests initialize the auth manager
simultaneously.
### What you think should happen instead
Concurrent requests to `/auth/token` should not cause server errors.
If my analysis is correct, `create_auth_manager()` should check for an
existing instance before creating a new one:
``` python
def create_auth_manager() -> BaseAuthManager:
if _AuthManagerState.instance is not None:
return _AuthManagerState.instance
auth_manager_cls = get_auth_manager_cls()
_AuthManagerState.instance = auth_manager_cls()
return _AuthManagerState.instance
```
### How to reproduce
1. Start Airflow with FAB auth manager
2. Send 2+ concurrent POST requests to `/auth/token`
(example python script)
```python
import asyncio
import httpx
async def main():
async with httpx.AsyncClient(timeout=30.0) as client:
tasks = [
client.post(
"http://localhost:8080/auth/token",
json={"username": "admin", "password": "admin"},
)
for _ in range(2)
]
results = await asyncio.gather(*tasks, return_exceptions=True)
for i, r in enumerate(results):
if isinstance(r, Exception):
print(f"Request {i}: Exception - {r}")
else:
print(f"Request {i}: {r.status_code} - {r.text[:200] if
r.status_code != 201 else 'OK'}")
asyncio.run(main())
```
Note: Other endpoints like /api/v2/dags work fine under concurrent load.
### Anything else
This issue started occurring after upgrading to recent versions.
(**airflow**: `3.0.6` -> **fab**: `2.4.1` -> `3.1.1`)
I suspect it may be related to recent refactoring (#59772, #59953), but I'm
not entirely certain.
Happy to provide more details or test any fixes.
### Are you willing to submit PR?
- [x] Yes I am willing to submit a PR!
### Code of Conduct
- [x] I agree to follow this project's [Code of
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]