Fix panic in shouldRetry type assertion and remove deprecated rand.Seed#1438
Open
Nepomuk5665 wants to merge 2 commits intodatabricks:mainfrom
Open
Fix panic in shouldRetry type assertion and remove deprecated rand.Seed#1438Nepomuk5665 wants to merge 2 commits intodatabricks:mainfrom
Nepomuk5665 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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