Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
### New Features and Improvements

### Bug Fixes
* Fix potential panic in `shouldRetry` function by using comma-ok idiom for type assertion ([#1438](https://github.com/databricks/databricks-sdk-go/pull/1438)).

### Documentation

### Internal Changes
* Remove deprecated `rand.Seed` call in retry backoff logic ([#1438](https://github.com/databricks/databricks-sdk-go/pull/1438)).

### API Changes
* Add `Force` field for [pipelines.DeletePipelineRequest](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/pipelines#DeletePipelineRequest).
5 changes: 2 additions & 3 deletions retries/retries.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func backoff(attempt int) time.Duration {
wait = maxWait
}
// add some random jitter
rand.Seed(time.Now().UnixNano())
jitter := rand.Intn(int(maxJitter)-int(minJitter)+1) + int(minJitter)
wait += time.Duration(jitter)
return wait
Expand Down Expand Up @@ -233,8 +232,8 @@ func shouldRetry(err error) bool {
if err == nil {
return false
}
e := err.(*Err)
if e == nil {
e, ok := err.(*Err)
if !ok || e == nil {
return false
}
return !e.Halt
Expand Down
17 changes: 17 additions & 0 deletions retries/retries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,23 @@ func TestRetriesNegativeTimeout(t *testing.T) {
assert.Equal(t, r.config.Timeout(), time.Duration(-1))
}

func TestShouldRetryWithNonErrType(t *testing.T) {
// Test that shouldRetry handles non-*Err types gracefully without panicking
regularError := errors.New("a regular error")
assert.False(t, shouldRetry(regularError))

// Test with nil
assert.False(t, shouldRetry(nil))

// Test with *Err that should not retry
haltErr := Halt(errors.New("halt error"))
assert.False(t, shouldRetry(haltErr))

// Test with *Err that should retry
continueErr := Continue(errors.New("continue error"))
assert.True(t, shouldRetry(continueErr))
}

func ExampleNew() {
// Default retries for 20 minutes on any error
New[int]()
Expand Down