Skip to content

Rate-limit JWKS fetch attempts while the endpoint is down - #73472

Closed
Eason09053360 wants to merge 1 commit into
apache:mainfrom
Eason09053360:fix-jwks-retry-interval-on-fetch-failure
Closed

Eason09053360 wants to merge 1 commit into
apache:mainfrom
Eason09053360:fix-jwks-retry-interval-on-fetch-failure

Conversation

@Eason09053360

Copy link
Copy Markdown
Contributor

Why

JWKS._should_fetch_jwks() only consulted refresh_retry_interval_secs once a keyset had loaded: not self._jwks short-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 through async_to_sync in 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, and status() 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?
  • Yes — Claude Code (Opus 5, Fable 5.1)

Generated-by: Claude Code (Opus 5, Fable 5.1) following the guidelines

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.
@boring-cyborg boring-cyborg Bot added the area:API Airflow's REST/HTTP API label Sep 21, 2026
This was referenced Sep 25, 2026
@potiuk potiuk added the closed because of open PR limit Closed as a one-time step of introducing the open pull request limit label Sep 25, 2026
@potiuk

potiuk commented Sep 25, 2026

Copy link
Copy Markdown
Member

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 gh pr reopen <PR_NUMBER> --repo apache/airflow. Reopen the ones you are ready to follow through - keep them rebased, respond to review comments and fix failing checks.

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

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 closed because of open PR limit Closed as a one-time step of introducing the open pull request limit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants