Skip to content

fix: protect FailingKubeClient.RecordedWaitOptions from data race#31925

Open
TerryHowe wants to merge 1 commit intohelm:mainfrom
TerryHowe:fix/race-failing-kube-client-wait-options
Open

fix: protect FailingKubeClient.RecordedWaitOptions from data race#31925
TerryHowe wants to merge 1 commit intohelm:mainfrom
TerryHowe:fix/race-failing-kube-client-wait-options

Conversation

@TerryHowe
Copy link
Contributor

Summary

  • Add sync.Mutex to FailingKubeClient to guard concurrent access to RecordedWaitOptions in GetWaiterWithOptions
  • Fixes data race detected by -race flag when concurrent goroutines (upgrade + rollback, install + uninstall) both call GetWaiterWithOptions on the same FailingKubeClient instance

Test plan

  • go test -race -run TestUpgradeRelease_Interrupted_RollbackOnFailure ./pkg/action passes
  • go test -race -run TestInstallRelease_RollbackOnFailure_Interrupted ./pkg/action passes
  • Full make test-unit passes

…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]>
Copilot AI review requested due to automatic review settings March 11, 2026 19:53
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Mar 11, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Mutex to FailingKubeClient to protect RecordedWaitOptions.
  • Lock/unlock around appending wait options in GetWaiterWithOptions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +165 to +167
f.mu.Lock()
f.RecordedWaitOptions = append(f.RecordedWaitOptions, opts...)
f.mu.Unlock()
Copy link
Member

@gjenkins8 gjenkins8 Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants