You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AsyncJwksFetcher._fetch_jwks catches asyncio.CancelledError in a bare except:. Cancelling an in-flight key lookup, including through asyncio.wait_for, is swallowed: get_key then forces a second request and raises TokenValidationError ("RSA Public Key ... was not found").
As a result, a timeout on an async token verification reports a missing key instead of a timeout, and the caller keeps waiting for the extra request. With a mocked 1.5 s JWKS request and asyncio.wait_for(fetcher.get_key("k"), 0.2):
Result
Requests
Elapsed
Before
TokenValidationError
2
1.70 s
After
TimeoutError
1
0.20 s
The handler now catches Exception, so cancellation propagates while ordinary fetch errors keep their existing behavior. No public API changes.
References
No linked issue; found by reading the code and reproduced with the regression test below.
Testing
tests/authentication/test_async_token_verifier.py adds two network-free tests: cancelling a real task propagates CancelledError after a single request, and an ordinary request error still reports the missing key. The cancellation test fails on the unchanged implementation.
The tests/authentication suite passes (114 tests). Tests under tests/wire were not run because they need the WireMock container. Ruff check passes on both changed files; the formatting differences ruff format --check reports in the source file are on lines this change does not touch.
This change adds unit test coverage
This change adds integration test coverage
This change has been tested on the latest version of the platform/language or why not (Python 3.15)
Changes
AsyncJwksFetcher._fetch_jwkscatchesasyncio.CancelledErrorin a bareexcept:. Cancelling an in-flight key lookup, including throughasyncio.wait_for, is swallowed:get_keythen forces a second request and raisesTokenValidationError("RSA Public Key ... was not found").As a result, a timeout on an async token verification reports a missing key instead of a timeout, and the caller keeps waiting for the extra request. With a mocked 1.5 s JWKS request and
asyncio.wait_for(fetcher.get_key("k"), 0.2):TokenValidationErrorTimeoutErrorThe handler now catches
Exception, so cancellation propagates while ordinary fetch errors keep their existing behavior. No public API changes.References
No linked issue; found by reading the code and reproduced with the regression test below.
Testing
tests/authentication/test_async_token_verifier.pyadds two network-free tests: cancelling a real task propagatesCancelledErrorafter a single request, and an ordinary request error still reports the missing key. The cancellation test fails on the unchanged implementation.The
tests/authenticationsuite passes (114 tests). Tests undertests/wirewere not run because they need the WireMock container. Ruff check passes on both changed files; the formatting differencesruff format --checkreports in the source file are on lines this change does not touch.Checklist
This contribution was generated with AI assistance.