fix: protect FailingKubeClient.RecordedWaitOptions from data race#31925
Open
fix: protect FailingKubeClient.RecordedWaitOptions from data race#31925
Conversation
…cess Add a sync.Mutex to guard the append to RecordedWaitOptions in GetWaiterWithOptions, fixing a data race detected by -race when concurrent goroutines (e.g. upgrade + rollback) both call GetWaiterWithOptions on the same FailingKubeClient instance. Fixes race failures in TestUpgradeRelease_Interrupted_RollbackOnFailure and TestInstallRelease_RollbackOnFailure_Interrupted. Signed-off-by: Terry Howe <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a data race in the test fake FailingKubeClient by guarding concurrent writes to RecordedWaitOptions when multiple goroutines call GetWaiterWithOptions on the same instance (e.g., upgrade + rollback or install + uninstall running concurrently under -race).
Changes:
- Add a
sync.MutextoFailingKubeClientto protectRecordedWaitOptions. - Lock/unlock around appending wait options in
GetWaiterWithOptions.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
gjenkins8
reviewed
Mar 12, 2026
Comment on lines
+165
to
+167
| f.mu.Lock() | ||
| f.RecordedWaitOptions = append(f.RecordedWaitOptions, opts...) | ||
| f.mu.Unlock() |
Member
There was a problem hiding this comment.
Suggested change
| f.mu.Lock() | |
| f.RecordedWaitOptions = append(f.RecordedWaitOptions, opts...) | |
| f.mu.Unlock() | |
| func (f *FailingKubeClient) appendRecordedWaitOptionsLocked(opts ...kube.WaitOption) { | |
| f.mu.Lock() | |
| defer f.mu.Unlock() | |
| f.RecordedWaitOptions = append(f.RecordedWaitOptions, opts...) | |
| } |
Make this a helper function and utilize defer? Or overkill? (I dislike non-deferred cleanup, future footgun)
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
sync.MutextoFailingKubeClientto guard concurrent access toRecordedWaitOptionsinGetWaiterWithOptions-raceflag when concurrent goroutines (upgrade + rollback, install + uninstall) both callGetWaiterWithOptionson the sameFailingKubeClientinstanceTest plan
go test -race -run TestUpgradeRelease_Interrupted_RollbackOnFailure ./pkg/actionpassesgo test -race -run TestInstallRelease_RollbackOnFailure_Interrupted ./pkg/actionpassesmake test-unitpasses