-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add configurable retry with exponential backoff to HTTP requests #34847
base: develop
Are you sure you want to change the base?
Conversation
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
Thanks for the contribution!!
|
@Gustrb
Regarding the pre-request handlers - point to be discussed. While the current implementation maintains consistency by running them on each attempt, we should discuss if this is the desired behavior or if we should preserve the handlers' result from the initial attempt? |
@Gustrb |
Hey @jannatkhandev I looked at the good and it mostly seems good to me, here is the course of actions I will take(and have been taking since Yesterday);
The issue of calling the pre-http handlers concerns me, it seems like something that could end up breaking some external integration and I am skeptical of not having it as a breaking change (it is not really a breaking change, but we would be potentially changing the behaviour of those hooks which is not ideal). I'll keep you updated on this one, thanks for the good work :) |
import type { AppBridges } from '../bridges/AppBridges'; | ||
import type { AppAccessorManager } from '../managers/AppAccessorManager'; | ||
|
||
export class Http implements IHttp { | ||
private static readonly DEFAULT_RETRY_CONFIG: IHttpRetryConfig = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think instead of having this hardcoded in here, we should have settings so the user can configure that in their workspace, wdyt @d-gubert ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or even a retry policy inside the app's settings, telling how should it retry. But I am not sure if it would not be overkill for now though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on the app's settings, like having default retry config for the app.
For the workspace setting as these changes revolve around apps using Http API, I feel it as an overkill.
Happy to make changes as advised :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, I think having it as a workspace setting would be the easier way off.
@Gustrb thanks for your prompt reply. |
Hey, I don't think we need to create sprints &/or tasks to implement those. |
@Gustrb Moved retry logic to higher order function as advised, PTAL. |
Proposed changes
Add HTTP Retry Mechanism
The HTTP accessor in the Apps Engine now supports automatic retries with exponential backoff for failed requests. This feature helps apps handle transient network failures and API rate limits more gracefully.
Configuration
The retry mechanism is disabled by default and can be enabled per request through the retry configuration option in the HTTP request options.
Default Configuration
Configuration Options
Usage Examples
Basic Usage with Default Settings
Custom Configuration
How It Works
When enabled, the retry mechanism will:
Error Handling
The final error from the last retry attempt will be thrown after all retries are exhausted. This error maintains the original structure and stack trace from the failed request.
Best Practices
Interface Definition
Implementation Details
The retry mechanism is implemented in the Http class of the Apps Engine. It preserves all existing functionality including:
Each retry attempt is not treated as a new request, all pre-request and pre-response handlers run once to prevent possible side effects.