-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 incorrect use of loop variable #16872
Conversation
Hi @renatolabs, thanks for your submission! Please could I get you to add a change log entry (https://github.com/hashicorp/vault/blob/main/CONTRIBUTING.md#changelog-entries)? |
3ab890d
to
aa40112
Compare
Done, thank you for the reminder! |
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.
Hey @renatolabs, thanks for this contribution!
False positives in tests can be really sneaky, I'm glad this can be fixed before a problem gets introduced unnoticed.
Would you mind triggering the CI so it has a chance to pass before I can approve the PR?
You can either apply the suggested change to the changelog or push an empty commit to trigger the validation steps:
git commit --allow-empty -m "trigger ci" && git push origin X
changelog/16872.txt
Outdated
@@ -0,0 +1,3 @@ | |||
```release-note:bug |
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.
Since the changes eliminate a redundant check and fixes tests hiding possible problems, but do not fix a logic error in the business code itself, may I suggest updating this to improvement
instead of bug
?
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.
Sure, changed to improvement
👍
aa40112
to
27b3470
Compare
Seems like the test failures are not flukes. I'm able to reproduce them when running the pull-request locally with I tried the proposed changes on the tip of hashicorp/vault and it seems to pass. Would it be possible to rebase to a newer commit to see if it does the trick? Thanks again. |
27b3470
to
6152781
Compare
Rebased 👍 |
Looks like there's a panic, which I think is introduced by this change:
|
I suppose this is related to this section // There is always one nil seal. We need to skip it so we don't start an empty Finalize-Seal-Shamir
// section.
if seal == nil {
continue
} which exists in But I'll let folks with more knowledge of the codebase to weigh in; let me know if you want me to any changes here! |
Well, I agree with your analysis: you've exposed a bug, not introduced one. And I agree it makes sense to check for nil seals in that loop so we don't panic. |
This fixes a couple of references to loop variables in parallel tests and deferred functions. When running a parallel test (calling `t.Parallel()`) combined with the table-driven pattern, it's necessary to copy the test case loop variable, otherwise only the last test case is exercised. This is documented in the `testing` package: https://pkg.go.dev/testing#hdr-Subtests_and_Sub_benchmarks `defer` statements that invoke a closure should also not reference a loop variable directly as the referenced value will change in each iteration of the loop. Issues were automatically found with the `loopvarcapture` linter.
6152781
to
5235770
Compare
Added a similar check to |
Thanks @renatolabs ! |
This fixes a couple of references to loop variables in parallel tests
and deferred functions. When running a parallel test (calling
t.Parallel()
) combined with the table-driven pattern, it's necessaryto copy the test case loop variable, otherwise only the last test case
is exercised. This is documented in the
testing
package:https://pkg.go.dev/testing#hdr-Subtests_and_Sub_benchmarks
defer
statements that invoke a closure should also not reference aloop variable directly as the referenced value will change in each
iteration of the loop.
Issues were automatically found with the
loopvarcapture
linter.