mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-11-26 11:16:30 +00:00
fix(metadata): retry discovery HTTP errors and recover in the background (#169)
A provider behind the same Traefik answers 404 while its router is not loaded, and 502 or 503 while it restarts. GetProviderMetadata returned these statuses as a plain error, so the startup retries stopped at the first attempt. After that, nothing retried until a request arrived, and that request got the 503 page (#147). - GetProviderMetadata returns a non-200 status as *HTTPError, so the startup retries apply to 429 and 5xx. - RetryConfig gets RetryableStatusCodes. MetadataFetchRetryConfig sets it to 404, so only discovery retries a 404. - If startup discovery fails, the init goroutine retries in the background (5 s, doubling up to 60 s, with jitter). It stops when metadata is adopted or when Close cancels the instance context. - GetMetadataWithRecovery takes a context, so Close also ends the startup retries. - Background attempts log at ERROR for the first three and every tenth, at DEBUG otherwise. A document with no usable issuer does not end recovery. A Close during the startup retries logs at DEBUG only. - The 503 served while metadata is unavailable or initialization times out carries Retry-After: 10, and the startup error log names the middleware. TestMetadataRecoveryOnProviderFailure and the issue152 cold-start test now serve 400 for a failed discovery, because startup retries 500 and 503 and these tests need init to fail at once.
This commit is contained in:
@@ -127,6 +127,19 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
|
||||
### Fixed
|
||||
|
||||
- **Provider metadata now recovers without a request (#147).** A discovery
|
||||
response of `404`, `429` or `5xx` is now retried during startup. Traefik
|
||||
answers `404` while the router of an IdP behind the same Traefik is not
|
||||
loaded yet. During these retries, requests wait up to 30 s for
|
||||
initialization, as they already do when the provider cannot be reached.
|
||||
If startup discovery still fails, each middleware instance
|
||||
retries in the background (5 s, doubling up to 60 s) until the provider
|
||||
answers or the instance closes. Before this change, an instance stayed
|
||||
broken until a request reached it. Background attempts log at ERROR for
|
||||
the first three and then for every tenth, and at DEBUG otherwise. The
|
||||
`503` served while metadata is unavailable or initialization times out
|
||||
now carries `Retry-After: 10`. The startup error log names the
|
||||
middleware.
|
||||
- SSE and WebSocket requests now get the configured `headers`, as normal
|
||||
requests do. The last release sent only `X-Forwarded-User` on these
|
||||
requests, so a backend that checks a shared-secret header answered `401`
|
||||
|
||||
Reference in New Issue
Block a user