ApiClient creates a new httpx.AsyncClient per JWKS / OIDC fetch with no timeout and no single-flight, causing "Unknown auth error" storms under load
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 48/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- python
调研方向
从 src/auth0_api_python/utils.py 开始,通过 utils.fetch_jwks、utils.fetch_oidc_metadata 和 InMemoryCache.get 跟踪 ApiClient._fetch_jwks 和 _fetch_oidc_metadata。检查 verify_request 如何到达这些缓存未命中路径,以及如何使用 httpx.AsyncClient。完成的标准是:JWKS 和 OIDC 的重新获取能够避免所报告的客户端、超时和并发请求失败行为,同时不改变成功身份验证的语义。
由索引模型根据 Issue 内容生成。
描述
Checklist
- I have looked into the Readme and Examples, and have not found a suitable solution or answer.
- I have looked into the API documentation and have not found a suitable solution or answer.
- I have searched the issues and have not found a suitable solution or answer.
- I have searched the Auth0 Community forums and have not found a suitable solution or answer.
- I agree to the terms within the Auth0 Code of Conduct.
Description
ApiClient._fetch_jwks and _fetch_oidc_metadata (via
utils.fetch_jwks / utils.fetch_oidc_metadata) construct a brand-new
httpx.AsyncClient() on every cache miss with no explicit timeout
configured, and there is no single-flight protection around the
refetch path. Combined, these turn routine cache expiry into a
self-inflicted outage under any non-trivial concurrency.
Reproduction
- Stand up a FastAPI service that calls
ApiClient.verify_request
on every authenticated route. - Drive ≥ ~30 RPS of authenticated requests against it (we hit it
on a 4 vCPU ECS Fargate task during a k6 load test). - Wait for the in-memory JWKS cache to expire — by default Auth0
returnsCache-Control: max-age=600, so this happens every ~10
minutes under steady load. - Observe a sudden burst of
httpx.ConnectTimeoutchained out of
ApiClient._fetch_jwks, surfacing to callers as opaque "Unknown
auth error" 5xx responses on every authenticated route until the
herd subsides. Sentry trace shows
auth0_api_python.errors.UnknownAuth0Exception←
httpx.ConnectTimeout.
Additional context
In src/auth0_api_python/utils.py
async def fetch_jwks(jwks_uri, custom_fetch=None):
...
async with httpx.AsyncClient() as client: # 1
resp = await client.get(jwks_uri) # 2
...
- No connection pooling across calls. A fresh client is created
and torn down per fetch. Every cache miss = a fresh TCP + TLS
handshake tohttps://<tenant>.auth0.com/. Under load this
exhausts ephemeral source-port budget on the host and slows
everything else on the box. - No explicit timeout.
httpx.AsyncClient()with notimeout=
uses httpx's default 5-second connect/read/write/pool budget. On a
stressed event loop or a slow Auth0 region that 5s budget is
routinely blown, raisinghttpx.ConnectTimeout/
httpx.ReadTimeout. Those bubble up into_fetch_jwksand the
caller seesConnectTimeoutchained toUnknownAuth0Exception—
not a 401, not a 503, just an opaque "unknown auth error". - No single-flight on refetch. When the in-memory cache expires
(InMemoryCache.getreturnsNone), every concurrent request
that reaches_fetch_jwkssimultaneously fires its own outbound
JWKS fetch. N requests in flight at the moment of expiry = N
concurrent JWKS calls to Auth0. Auth0 throttles some of them, the
others time out per (1) and (2), and any request that lost the
race fails auth.
The same three problems apply verbatim to fetch_oidc_metadata and
_fetch_oidc_metadata.
auth0-api-python version
1.0.0b8
Python version
3.11
- 主要语言
- Python
- 星标
- 4
- 派生
- 9
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
auth0/auth0-api-python 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
auth0/auth0-api-python#92 · 2 条评论 · 1 个 reaction ·
-
难度 5/5 一周以上 新手友好度 35/100
auth0/auth0-api-python#113 ·
-
难度 2/5 1-3 小时 新手友好度 52/100
auth0/auth0-api-python#59 ·
查看 auth0/auth0-api-python 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 2/5 1-3 小时 新手友好度 88/100
use-agent-os/agent-os#3314 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
BasedHardware/omi#15662 · 1 条评论 ·
-
documentation help wanted
难度 2/5 1-3 小时 新手友好度 90/100
-
难度 2/5 1-3 小时 新手友好度 62/100
AiursoftWeb/AnduinOS-2#19 ·