-
Notifications
You must be signed in to change notification settings - Fork 137
tapgarden: copy MintingBatches defensively #1903
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
Conversation
The 'pendingBatches' here are references that are updated by the gardener goroutine. Previously the references themselves were handed to callers, rather than copies, meaning that callers could have inconsistent views of data if a reference was updated by the gardener. This commit merely copies each 'pendingBatch' before passing it on.
Summary of ChangesHello @jtobin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the robustness of the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces defensive copying of MintingBatch instances before they are passed to other parts of the system, which is a good practice to prevent race conditions and unexpected mutations. The changes in gardener() correctly apply this pattern when handling seedlingReqs and stateReqs.
However, I've identified a potential issue with the MintingBatch.Copy() method itself. It performs a shallow copy of the Seedlings map, which means that while the map itself is new, it contains pointers to the same Seedling objects as the original. Any modification to these Seedling objects will be reflected in both the original and the copied batch. I've left a specific comment on this. While fixing the Copy method is likely outside the scope of this PR, it's an important consideration for making these copies truly defensive.
Pull Request Test Coverage Report for Build 19963225879Details
💛 - Coveralls |
|
The CI jobs for unit-race and unit-cover, which frequently trigger tapgarden flakes, at least worked the first time here, which is encouraging. (EDIT: and again, on force push!) |
The Copy() method for MintingBatch previously produced a shallow copy of the Seedlings map. This commit ensures that each value in the map is a deep copy as well.
| seedlingCopy := *v | ||
| batchCopy.Seedlings[k] = &seedlingCopy |
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.
Maybe we need additional unit test coverage for Copy() somewhere?
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.
We can look into this further in a future PR.
The 'pendingBatches' here are references that are updated by the gardener goroutine. Previously the references themselves were handed to callers, meaning that callers could have inconsistent views of data if a reference was updated by the gardener. This commit merely copies each 'pendingBatch' before passing it on.
This may alleviate one or both of #1882 and #1885, as I expect this to improve the semantics of assertPendingBatchExists in planter_test.go in particular (and thus queueInitialBatch, testMintingCancelFinalize, testFundSealBeforeFinalize), but it seems an improvement regardless.