fix: timeout while waiting for SSH to become available

In #68 I reduced the general limits for the backoff, thinking that it
would speed up the upload on average because it was retrying faster. But
because it was retrying faster, the 10 available retries were used up
before SSH became available.

The new 100 retries match the 3 minutes of total timeout that the
previous solution had, and should fix all issues.

In addition I discovered that my implementation in
`hcloudimages/backoff.ExponentialBackoffWithLimit` has a bug where the
calculated offset could overflow before the limit was applied, resulting
in negative durations. I did not fix the issue because `hcloud-go`
provides such a method natively nowadays. Instead I marked the method as
deprected, to be removed in a later release.
This commit is contained in:
Julian Tölle 2025-05-09 15:55:06 +02:00
parent ba421d7dd8
commit c1f086867d
No known key found for this signature in database
GPG key ID: 001A85FE011D3C73
4 changed files with 9 additions and 5 deletions

View file

@ -9,7 +9,6 @@ import (
"github.com/spf13/cobra"
"github.com/apricote/hcloud-upload-image/hcloudimages"
"github.com/apricote/hcloud-upload-image/hcloudimages/backoff"
"github.com/apricote/hcloud-upload-image/hcloudimages/contextlogger"
"github.com/apricote/hcloud-upload-image/internal/ui"
"github.com/apricote/hcloud-upload-image/internal/version"
@ -89,7 +88,7 @@ func initClient(cmd *cobra.Command, _ []string) {
opts := []hcloud.ClientOption{
hcloud.WithToken(os.Getenv("HCLOUD_TOKEN")),
hcloud.WithApplication("hcloud-upload-image", version.Version),
hcloud.WithPollOpts(hcloud.PollOpts{BackoffFunc: backoff.ExponentialBackoffWithLimit(2, 1*time.Second, 30*time.Second)}),
hcloud.WithPollOpts(hcloud.PollOpts{BackoffFunc: hcloud.ExponentialBackoffWithOpts(hcloud.ExponentialBackoffOpts{Multiplier: 2, Base: 1 * time.Second, Cap: 30 * time.Second})}),
}
if os.Getenv("HCLOUD_DEBUG") != "" || verbose >= 2 {