fix(getter): race condition when SetClient is called#466
Open
srevinsaju wants to merge 1 commit intohashicorp:mainfrom
Open
fix(getter): race condition when SetClient is called#466srevinsaju wants to merge 1 commit intohashicorp:mainfrom
srevinsaju wants to merge 1 commit intohashicorp:mainfrom
Conversation
this is a non-breaking change. this fixes an issue when Clients are created and called concurrently. clients called SetClient on each of the Getters. When no getters were provided, it modified the clients of the default getters defined in a map. Since the map was mutated from multiple goroutines, it creates a race condition 'concurrent map writes'. The issue is mitigated by creating a new copy of Getters for every new client created. SetClient now modifies its own copy of the Getter, not the default Getters
CreatorHead
requested changes
Jan 14, 2026
Contributor
CreatorHead
left a comment
There was a problem hiding this comment.
Thanks for the fix, the race is real. One concern: this changes behavior when Client.Getters is nil. Previously we used the package-level Getters map, which many consumers may customize (e.g. adding schemes). With c.Getters = DefaultGetters() we would ignore those customizations. Can we instead copy the global Getters map into a per-client map (so we avoid shared mutation, but still honor user overrides)? Also, could you add a small test that reproduces the race with -race and verifies the fix?
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.
This is a non-breaking change. This fixes an issue when Clients are created and called concurrently.
Clients called
SetClienton each of theGetters. When no getters were provided, it modified the clients of the default getters defined in theGettersmap.Since the map was mutated from multiple goroutines, it creates a race condition 'concurrent map writes'. The issue is mitigated by creating a new copy of
GettersusingDefaultGetters()function for every new client created.SetClientnow modifies its own copy of theGetter, not the defaultGetters.To reproduce the issue:
go run -race .