-
Notifications
You must be signed in to change notification settings - Fork 492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix panic on closing nil db #3175
Fix panic on closing nil db #3175
Conversation
When account.FillDBWithParticipationKeys fails and returns an error, e.g. if the key already exists, newPart will be invalid and should not be closed. When Close is called, it will panic.
FillDBWithParticipationKeys will return empty PersistedParticipation when lastValid is less than firstValid. When this happens, newPart will not have partdb in newPart.Store, instead, will have an empty object. Calling Close on the empty object will call close on nil Accessor pointer and panic. This change avoids using the returned object with non-nil error, and properly closes the db with the valid object. Added test to varify the proper handling of the different errors returned from FillDBWithParticipationKeys and handled by GenParticipationKeysTo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great, but please fix the review dog comments..
Codecov Report
@@ Coverage Diff @@
## master #3175 +/- ##
==========================================
- Coverage 43.81% 43.77% -0.05%
==========================================
Files 392 392
Lines 86885 86885
==========================================
- Hits 38073 38033 -40
- Misses 42782 42812 +30
- Partials 6030 6040 +10
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Summary
FillDBWithParticipationKeys will return empty PersistedParticipation when lastValid is less than firstValid.
When this happens, newPart will not have partdb in newPart.Store, instead, will have an empty object.
Calling Close on the empty object will call close on nil Accessor pointer and panic.
This change avoids using the returned object with non-nil error, and properly closes the db with the valid object.
Test Plan
Added test to verify the proper handling of the different errors returned from FillDBWithParticipationKeys and handled by GenParticipationKeysTo.