Fix panic in shouldRetry type assertion and remove deprecated rand.Seed#1438
Fix panic in shouldRetry type assertion and remove deprecated rand.Seed#1438Nepomuk5665 wants to merge 2 commits intodatabricks:mainfrom
Conversation
- 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.
63db9d1 to
0cefa26
Compare
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 15 days if no further activity occurs. If this PR is still relevant, please leave a comment or push new changes to keep it open. Thank you for your contributions. |
|
Hi @Nepomuk5665, thanks for taking the time to contribute. I had a closer look at the The Would you be open to scoping this PR down to the |
Summary
shouldRetryfunction by using comma-ok idiom for type assertionrand.Seedcall that was re-seeding on every backoff attemptshouldRetrywith various error typesBug Description
Type Assertion Panic
The
shouldRetryfunction inretries/retries.goused a direct type assertion:While this function is internal and typically receives
*Errvalues fromWaitandPollfunctions, a direct type assertion is unsafe. If any code path passes a non-*Errerror, the program will panic with a runtime error.The fix uses the comma-ok idiom to safely handle any error type:
Deprecated rand.Seed
The
backofffunction calledrand.Seed(time.Now().UnixNano())on every invocation. This has two issues:Testing
TestShouldRetryWithNonErrTypethat verifies the fix handles various error types without panicking