Skip to content

Commit 8d1b665

Browse files
authored
fix: ignore nil backoff function when configuring poll or retry options (#587)
Ensure the back off function is not nil when a user only configures the `RetryOpts.MaxRetries` value. Fixes to #586
1 parent 3f1c787 commit 8d1b665

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

hcloud/client.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,13 @@ type PollOpts struct {
171171
}
172172

173173
// WithPollOpts configures a Client to use the specified options when polling from the API.
174+
//
175+
// If [PollOpts.BackoffFunc] is nil, the existing backoff function will be preserved.
174176
func WithPollOpts(opts PollOpts) ClientOption {
175177
return func(client *Client) {
176-
client.pollBackoffFunc = opts.BackoffFunc
178+
if opts.BackoffFunc != nil {
179+
client.pollBackoffFunc = opts.BackoffFunc
180+
}
177181
}
178182
}
179183

@@ -195,9 +199,13 @@ type RetryOpts struct {
195199

196200
// WithRetryOpts configures a Client to use the specified options when retrying API
197201
// requests.
202+
//
203+
// If [RetryOpts.BackoffFunc] is nil, the existing backoff function will be preserved.
198204
func WithRetryOpts(opts RetryOpts) ClientOption {
199205
return func(client *Client) {
200-
client.retryBackoffFunc = opts.BackoffFunc
206+
if opts.BackoffFunc != nil {
207+
client.retryBackoffFunc = opts.BackoffFunc
208+
}
201209
client.retryMaxRetries = opts.MaxRetries
202210
}
203211
}

0 commit comments

Comments
 (0)