Commit 4ccea10
committed
fix(connect): catch authlib OAuthError in background token refresh thread
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 (#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 #21101 parent ae327ca commit 4ccea10
2 files changed
Lines changed: 51 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
591 | 592 | | |
592 | 593 | | |
593 | 594 | | |
594 | | - | |
| 595 | + | |
595 | 596 | | |
| 597 | + | |
| 598 | + | |
596 | 599 | | |
597 | 600 | | |
598 | 601 | | |
| |||
0 commit comments