fix(connect): catch authlib OAuthError in background token refresh thread - #2111
Open
Solaris-star wants to merge 1 commit into
Open
fix(connect): catch authlib OAuthError in background token refresh thread#2111Solaris-star wants to merge 1 commit into
Solaris-star wants to merge 1 commit into
Conversation
…read The periodic_refresh_token daemon thread only caught httpx.HTTPError. When the identity provider rejects a refresh at the OAuth2 protocol level (e.g. Keycloak returns 400 invalid_grant due to token rotation, reuse, revocation, or session expiry), authlib raises OAuthError which inherits from AuthlibBaseError — NOT from httpx.HTTPError. The uncaught exception killed the daemon thread silently, permanently breaking the connection's ability to refresh tokens (weaviate#2110). Add AuthlibBaseError to the except clause so both transport-level (HTTPError) and protocol-level (OAuthError) failures are caught, warned, and retried after 1 second. Adds test/test_token_refresh.py with 4 tests verifying: - AuthlibBaseError is NOT a subclass of HTTPError (confirms the bug) - The fixed except clause catches AuthlibBaseError - HTTPError is still caught (no regression) - Concrete OAuthError subclass is also caught Fixes weaviate#2110
There was a problem hiding this comment.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Infrastructure as Code | View in Orca | ||
| SAST | View in Orca | ||
| Secrets | View in Orca | ||
| Vulnerabilities | View in Orca |
|
To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge. |
Author
|
I have read and agree to the Contributor License Agreement. |
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.
Summary
Fixes #2110
The
periodic_refresh_tokendaemon thread only caughthttpx.HTTPError. When the identity provider rejects a refresh at the OAuth2 protocol level (e.g. Keycloak returns400 invalid_grantdue to token rotation, reuse, revocation, or session expiry), authlib raisesOAuthErrorwhich inherits fromAuthlibBaseError— NOT fromhttpx.HTTPError. The uncaught exception killed the daemon thread silently, permanently breaking the connection's ability to refresh tokens.Fix
Add
AuthlibBaseErrorto the except clause so both transport-level (HTTPError) and protocol-level (OAuthError) failures are caught, warned, and retried after 1 second:Tests
Added
test/test_token_refresh.pywith 4 tests:test_authlib_base_error_is_not_http_error— confirmsAuthlibBaseErroris NOT a subclass ofHTTPError(proves the bug exists)test_authlib_base_error_caught_by_fixed_except_clause— the fixed clause catches ittest_http_error_still_caught_by_fixed_except_clause— no regression on existing behaviortest_oauth_error_subclass_caught— concreteOAuthErrorsubclass is also caught