feat: add optional HTTP retry for Web API (429, 5xx, connection errors)#1532
Open
olegbespalov wants to merge 2 commits intoslack-go:masterfrom
Open
feat: add optional HTTP retry for Web API (429, 5xx, connection errors)#1532olegbespalov wants to merge 2 commits intoslack-go:masterfrom
olegbespalov wants to merge 2 commits intoslack-go:masterfrom
Conversation
Add OptionRetry(n) and OptionRetryConfig(cfg). Retries are off by default. OptionRetry enables 429-only retries; OptionRetryConfig supports pluggable handlers (connection, 429, opt-in 5xx). Respect Retry-After for 429 and exponential backoff for 5xx/connection. Set GetBody on form/JSON so body can be re-sent; streaming requests are not retried. Aligns with Python SDK.
6d7fa97 to
af8a302
Compare
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.
What?
This PR adds optional HTTP retries for the Web API client. Retries are off by default. You can turn them on with
OptionRetry(n)for simple 429-only retries orOptionRetryConfig(cfg)when you want full control.It's also possible to opt-in 5xx retries via NewServerErrorRetryHandler(cfg). For 5xx and connection errors, we also use exponential backoff from the config. Multipart and other streaming requests are left as-is and are not retried.
Why?
Without retries, a single 429, 5xx, or connection blip often forces callers to implement their retry and backoff. Enabling retries via one option improves reliability under rate limits, server issues, and flaky networks without pushing that logic onto every user.
Defaulting to 429-only keeps behavior predictable; users who want connection or 5xx retries can add the right handlers.
Closes #1531