Implement retry logic in HTTP Send method#5857
Conversation
Added retry logic with exponential backoff to the Send method for HTTP requests, improving error handling and resilience against transient failures.
|
Thanks, but could you explain why this is necessary? |
In my actual usage, I found that every week some pipelines randomly fail to start due to HTTP request failures, possibly because the HTTP service is unstable. Therefore, retrying HTTP requests is necessary. |
|
You're using a config extension? |
Yes, my entire CI pipeline relies on External Configuration API |
|
Ok, so for backoffs we use |
Replaced manual backoff calculation with backoff package for retry logic.
ok , done |
Fix lint issues
|
Would it be possible to let the lib handle the waiting etc, so we don't need a for loop etc.? Similar to how this is done in https://github.com/woodpecker-ci/woodpecker/blob/main/cmd/server/server.go#L96-L104. |
Refactor HTTP request retry logic with backoff
done |
Removed initial backoff duration and maximum backoff interval constants from the Send function.
Removed unused error field from result type in HTTP utility. fix lint
|
Does it need result type at all, can't it just return int? |
Dear maintainers, if there are any details that still need to be adjusted, please feel free to make the changes directly. @qwerty287 @lafriks |
|
@lafriks changed that, do you want to check it out again? |
|
@woodpecker-ci/maintainers as I modified quite some parts of this, does somebody else wants to review? |
xoxys
left a comment
There was a problem hiding this comment.
Code LGTM, not tested. As we talk about it, can we add tests?
|
Not sure how - we can of course send requests to non-existing servers, but then we somehow have to catch that and count the tries. If the server itself is reachable it won't retry… Do you have an idea? |
|
You could start an http server in the test with a handler that returns 500 the first x times and then a config. Similar to |
|
Ah, sorry, I thought any status code is not retried. Yes, this works. |
|
Test added in a9e49a1 |
Added retry logic with exponential backoff to the Send method for HTTP requests, improving error handling and resilience against transient failures.