Skip to content

Implement retry logic in HTTP Send method#5857

Merged
qwerty287 merged 13 commits into
woodpecker-ci:mainfrom
myselfghost:f-http-send-retry
Jan 21, 2026
Merged

Implement retry logic in HTTP Send method#5857
qwerty287 merged 13 commits into
woodpecker-ci:mainfrom
myselfghost:f-http-send-retry

Conversation

@myselfghost

Copy link
Copy Markdown
Contributor

Added retry logic with exponential backoff to the Send method for HTTP requests, improving error handling and resilience against transient failures.

Added retry logic with exponential backoff to the Send method for HTTP requests, improving error handling and resilience against transient failures.
@qwerty287

Copy link
Copy Markdown
Contributor

Thanks, but could you explain why this is necessary?

@myselfghost

myselfghost commented Dec 14, 2025

Copy link
Copy Markdown
Contributor Author

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.

@qwerty287

Copy link
Copy Markdown
Contributor

You're using a config extension?

@myselfghost

Copy link
Copy Markdown
Contributor Author

You're using a config extension?

Yes, my entire CI pipeline relies on External Configuration API

@qwerty287

Copy link
Copy Markdown
Contributor

Ok, so for backoffs we use github.com/cenkalti/backoff/v5. Can you use it?

Replaced manual backoff calculation with backoff package for retry logic.
@myselfghost

Copy link
Copy Markdown
Contributor Author

Ok, so for backoffs we use github.com/cenkalti/backoff/v5. Can you use it?

ok , done

Fix lint issues
@qwerty287

Copy link
Copy Markdown
Contributor

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.

@qwerty287 qwerty287 added the enhancement improve existing features label Dec 19, 2025
Refactor HTTP request retry logic with backoff
@myselfghost

Copy link
Copy Markdown
Contributor Author

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.

done

Comment thread server/services/utils/http.go Outdated
Comment thread server/services/utils/http.go Outdated
qwerty287 and others added 4 commits December 20, 2025 09:11
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
@lafriks

lafriks commented Dec 20, 2025

Copy link
Copy Markdown
Contributor

Does it need result type at all, can't it just return int?

@myselfghost

Copy link
Copy Markdown
Contributor Author

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

@qwerty287

Copy link
Copy Markdown
Contributor

@lafriks changed that, do you want to check it out again?

@qwerty287

Copy link
Copy Markdown
Contributor

@woodpecker-ci/maintainers as I modified quite some parts of this, does somebody else wants to review?

@xoxys xoxys left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM, not tested. As we talk about it, can we add tests?

@qwerty287

Copy link
Copy Markdown
Contributor

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?

@anbraten

Copy link
Copy Markdown
Member

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

ts := httptest.NewServer(http.HandlerFunc(fixtureHandler))

@qwerty287

Copy link
Copy Markdown
Contributor

Ah, sorry, I thought any status code is not retried. Yes, this works.

@qwerty287

Copy link
Copy Markdown
Contributor

Test added in a9e49a1

@qwerty287 qwerty287 merged commit 650833e into woodpecker-ci:main Jan 21, 2026
7 checks passed
@woodpecker-bot woodpecker-bot mentioned this pull request Jan 21, 2026
1 task
@woodpecker-bot woodpecker-bot mentioned this pull request Apr 1, 2026
1 task
@woodpecker-bot woodpecker-bot mentioned this pull request Apr 15, 2026
1 task
@woodpecker-bot woodpecker-bot mentioned this pull request Apr 29, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement improve existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants