Repository navigation
fix: propagate async JWKS fetch cancellation - #910
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.