PCTEJA opened a new pull request, #77527:
URL: https://github.com/apache/airflow/pull/77527

   With a MySQL metadata database, the first authenticated API request after 
the connection goes idle fails with HTTP 500. The revoked-token lookup in 
`BaseAuthManager.get_user_from_token` runs on the pooled session, and when 
MySQL has already dropped the connection (`wait_timeout` exceeded, error 4031), 
the query raises before the FastAPI auth manager's own recovery can discard the 
stale session and retry. The next request succeeds because the failed attempt 
already evicted the dead connection.
   
   This mirrors the recovery that `FABAuthManager.deserialize_user` already 
does: on a database error from the revocation lookup, discard the scoped 
session and retry the lookup once. If the retry also fails, the error 
propagates unchanged, so a genuinely unavailable database still surfaces 
instead of being masked.
   
   This revives the approach from #71444, which the reporter ran in production 
for weeks before it was closed by the stale bot; the fix here applies it at the 
shared `BaseAuthManager` level so every auth manager that relies on the 
revoked-token check gets the same recovery.
   
   closes: #71395
   
   ## Verification
   
   - Added four tests to `test_base_auth_manager.py` covering the recovery 
path: the retry succeeds after a stale-connection error, a revoked token is 
still rejected after a retry, a persistent error propagates after exactly one 
retry, and recovery still works when `settings.Session` is `None`.
   - The new tests fail against the unmodified code, and a negative control 
(call site temporarily reverted to the direct `RevokedToken.is_revoked` call) 
fails with exactly the reported `sqlalchemy.exc.OperationalError: (4031, 'The 
client was disconnected...')`.
   - 
`airflow-core/tests/unit/api_fastapi/auth/managers/test_base_auth_manager.py`: 
73 passed. Ruff format and check pass; mypy for airflow-core passes.
   - No live MySQL reproduction was possible in this environment (no 
Docker/breeze), so verification of the failure mode uses a mocked MySQL 4031 
error; CI's MySQL-backed tests are the remaining check for the real database 
path.
   - No API route or schema is touched, so the generated OpenAPI spec is 
unchanged.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Muse Spark following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   


-- 
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]

Reply via email to