hcloud-go icon indicating copy to clipboard operation
hcloud-go copied to clipboard

Retry transient HTTP Errors

Open mschfh opened this issue 1 year ago • 6 comments

Please (re)implement retries for transient HTTP error codes (502, 503, 504, etc) with sensible defaults

mschfh avatar Aug 29 '23 10:08 mschfh

This issue has been marked as stale because it has not had recent activity. The bot will close the issue if no further action occurs.

github-actions[bot] avatar Nov 27 '23 12:11 github-actions[bot]

Hey @mschfh,

plainly retrying requests could be a bit dangerous, as we do not have an idempotent API. Actions might be taken twice, if the actual API request arrived at the backend, but then some proxy in the middle fails the request.

Do you know of any SDKs/API Clients which do this?

apricote avatar Dec 04 '23 09:12 apricote

afaik aws's SDK does this

https://docs.aws.amazon.com/sdkref/latest/guide/feature-retry-behavior.html

alexandernst avatar Dec 14 '23 21:12 alexandernst

This issue has been marked as stale because it has not had recent activity. The bot will close the issue if no further action occurs.

github-actions[bot] avatar Mar 14 '24 12:03 github-actions[bot]

unstale

alexandernst avatar Mar 14 '24 12:03 alexandernst

Until we find out the best approach to solve this, you may use an external library that implement a retry round tripper:

package main

import (
	"net/http"

	"github.com/hashicorp/go-retryablehttp"
	"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

func main() {
	token := "YOUR_API_TOKEN"

	httpClient := &http.Client{}
	httpClient.Transport = &retryablehttp.RoundTripper{}

	hcloud.NewClient(
		hcloud.WithToken(token),
		hcloud.WithHTTPClient(httpClient),
	)
}

jooola avatar May 06 '24 09:05 jooola