Repository navigation
Rate-limit JWKS fetch attempts while the endpoint is down - #73472
Eason09053360 wants to merge 1 commit into
Conversation
The retry interval on JWKS was only consulted after a keyset had been loaded once: `not self._jwks` short-circuited the whole expression, so while the endpoint was down every incoming request issued its own remote fetch, amplifying an IdP outage into request-rate traffic against it and stalling the API server on the timeouts. Gating the never-loaded case on the retry interval means concurrent cold-start requests must share the first in-flight fetch instead of being turned away with no keyset, so fetches are now single-flight. The lock is kept per event loop because validated_claims() drives this class through async_to_sync, which runs each call in a throwaway loop. status() now requires a loaded keyset before reporting healthy, since a pending retry no longer implies the keys are there.
|
Hello @Eason09053360 - thank you for your contributions to Apache Airflow! The Airflow community has introduced a limit of 5 open pull requests at a time for contributors without write access to the repository. You currently have 33 open pull requests, so - as a one-time step of introducing the limit - we closed the ones where maintainers have not engaged yet:
These pull requests stay open because maintainers are already engaged in them - they count towards your limit:
This is not a judgement of you or of your changes. We never told contributors before that opening many pull requests at once was a problem, so there is nothing to feel bad about - and nothing is lost: your branches, commits and the review history stay where they are. What we ask you to do is to make your first prioritization decision: choose which of the pull requests above matter most to you, and reopen them (up to 5 open at a time, including the ones still open) with the "Reopen pull request" button or While your pull requests are waiting for review, the most valuable thing you can do is help in other ways - reviewing other contributors' pull requests, helping with issues, and taking part in the discussions on the devlist and Slack. Why we introduced the limit, what it means for you and how to reopen or restore a pull request is explained in https://github.com/apache/airflow/blob/main/contributing-docs/32_open_pull_request_limit.rst. Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting |
Why
JWKS._should_fetch_jwks()only consultedrefresh_retry_interval_secsonce a keyset had loaded:not self._jwksshort-circuits the check, so while the JWKS endpoint is down every incoming request issues its own remote fetch. An IdP outage turns into request-rate traffic against it and the API server stalls on the timeouts, contrary to the docstring's "minimum interval between attempts". Core and Execution API validators share this class.What
airflow-core/src/airflow/api_fastapi/auth/tokens.py: the retry interval now gates the never-loaded case too, and fetches are single-flight with a per-event-loop lock (validated_claims()runs throughasync_to_syncin a throwaway loop) so concurrent cold-start requests share the first fetch instead of failing with no keyset; an in-flight refresh keeps serving the existing keyset, andstatus()requires a loaded keyset before reporting healthy.test_tokens.py: one fetch per retry window against a 500-ing endpoint, one shared fetch for 10 concurrent cold-start calls, and lock reuse across event loops.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 5, Fable 5.1) following the guidelines