userconfig: protect aliases map against concurrent access #1456
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.
What I did
Config.Aliasesmap with a mutex.Related issue
Fixes #1454
What was the bug
The
Config.Aliasesmap was accessed concurrently without synchronization.When multiple goroutines (or parallel tests) called methods like
SetAlias,GetAlias, orDeleteAliasat the same time, this resulted in:fatal error: concurrent map writesBecause Go maps are not thread-safe, even concurrent reads and writes could trigger panics.
Description
In the previous implementation, the
Configstruct exposed methods that mutated or read from theAliasesmap without any form of synchronization.When these methods were invoked concurrently—most notably from tests using
t.Parallel()—the runtime detected unsafe concurrent access and crashed.This change introduces a mutex inside
Configand ensures that all accesses to theAliasesmap are properly synchronized.Result
Validation — Reproducing the original failure
The issue was originally reproducible by repeatedly running the userconfig test suite, which intermittently failed with a
concurrent map accesspanic.Validation — Race detector
The fix was also validated using the Go race detector:
Validation — Full build
After the fix, the full test suite (
go test ./...) runs successfully without failures.