Skip to content

Fix panic in shouldRetry type assertion and remove deprecated rand.Seed#1438

Open
Nepomuk5665 wants to merge 2 commits intodatabricks:mainfrom
Nepomuk5665:fix-shouldretry-type-assertion
Open

Fix panic in shouldRetry type assertion and remove deprecated rand.Seed#1438
Nepomuk5665 wants to merge 2 commits intodatabricks:mainfrom
Nepomuk5665:fix-shouldretry-type-assertion

Conversation

@Nepomuk5665
Copy link

Summary

  • Fix potential panic in shouldRetry function by using comma-ok idiom for type assertion
  • Remove deprecated rand.Seed call that was re-seeding on every backoff attempt
  • Add test coverage for shouldRetry with various error types

Bug Description

Type Assertion Panic

The shouldRetry function in retries/retries.go used a direct type assertion:

e := err.(*Err)  // This panics if err is not *Err type

While this function is internal and typically receives *Err values from Wait and Poll functions, a direct type assertion is unsafe. If any code path passes a non-*Err error, the program will panic with a runtime error.

The fix uses the comma-ok idiom to safely handle any error type:

e, ok := err.(*Err)
if !ok || e == nil {
    return false
}

Deprecated rand.Seed

The backoff function called rand.Seed(time.Now().UnixNano()) on every invocation. This has two issues:

  1. Deprecated since Go 1.20: The global random number generator is now automatically seeded
  2. Wasteful: Re-seeding on every retry attempt is unnecessary and has performance implications

Testing

  • All existing tests pass
  • Added new test TestShouldRetryWithNonErrType that verifies the fix handles various error types without panicking

- Use comma-ok idiom in shouldRetry to handle non-*Err error types safely
- Remove deprecated rand.Seed call that was re-seeding on every backoff
- Add test coverage for shouldRetry with various error types

The shouldRetry function previously used a direct type assertion
that would panic if passed an error not of type *Err. While this
function is internal and typically receives *Err values, the type
assertion should be safe to handle unexpected inputs.

The rand.Seed call has been deprecated since Go 1.20 as the global
random number generator is now automatically seeded. Additionally,
calling Seed on every retry attempt was wasteful.
@Nepomuk5665 Nepomuk5665 force-pushed the fix-shouldretry-type-assertion branch from 63db9d1 to 0cefa26 Compare January 23, 2026 19:28
@github-actions
Copy link

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/sdk-go

Inputs:

  • PR number: 1438
  • Commit SHA: 0cefa2609c108943d86c68300e2cce5ca343f817

Checks will be approved automatically on success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant