fix(connection): retry transient 429 / 5xx instead of failing the request - #93
Merged
Merged
Conversation
…uest Closes CJNE#61 (504 during command polling) and addresses CJNE#63 (429 marking every Porsche Connect entity Unavailable until HA restart). Per the maintainer comment on CJNE#63: > "I'll look into having some automatic retry after some time to get it > up again." And the body of CJNE#61: > "should not cause an exception (at least not until having retried one > or two times). Note that the remote service call itself was > successful, it was only the call for status that timed out." Implementation: - `Connection.request` retries up to 3 times on {429, 502, 503, 504}. - The server-provided `Retry-After` header is respected when present (RFC 9110 §10.2.3) and is a positive integer of seconds. - Otherwise: exponential backoff (1s, 2s, 4s) with up to 0.3s of jitter to spread out concurrent retries. - Per-retry delay capped at 30s so a misbehaving server can't pin a caller for minutes. - Non-transient 4xx (e.g. 400 / 401 / 404) still raise immediately via `PorscheExceptionError` — same behaviour as before. - Token-lock acquisition moved out of the retry loop; only the actual HTTP call is retried (`ensure_valid_token` is a fast no-op when the token is still valid). Concrete repro of the previous behaviour: >>> # Previously, a single 504 from /commands/{id} would crash the >>> # coordinator update, marking every HA entity Unavailable. >>> # After this patch, the 504 is retried up to 3 times before >>> # bubbling up. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Closes #61 (504 during command polling) and addresses #63 (429 marking every Porsche Connect entity Unavailable until HA restart).
Per the maintainer comment on #63:
And the body of #61:
Implementation:
Connection.requestretries up to 3 times on {429, 502, 503, 504}.Retry-Afterheader is respected when present (RFC 9110 §10.2.3) and is a positive integer of seconds.PorscheExceptionError— same behaviour as before.ensure_valid_tokenis a fast no-op when the token is still valid).Concrete repro of the previous behaviour: