fix: fix two thread-safety issues#53
Merged
lzap merged 5 commits intoosbuild:mainfrom Apr 30, 2026
Merged
Conversation
The global rand.Source in pkg/strc/context.go was not thread-safe, causing potential race conditions when NewTraceID() or NewSpanID() were called concurrently from multiple goroutines. This commit: - Replaces math/rand with math/rand/v2 which has a thread-safe global generator - Removes the global rand.Source and mutex approach - Updates tests to verify format/length instead of specific random values (since math/rand/v2 global generator cannot be seeded for deterministic tests) - Adds TestConcurrentIDGeneration to verify thread safety Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
The global proxy variable in pkg/echo/proxy.go could have race conditions if SetDefault() and Default() were called concurrently. This commit replaces the plain pointer with sync/atomic.Pointer to ensure thread-safe access, consistent with the approach used in pkg/logrus/proxy.go and pkg/strc/trace.go. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
croissanne
approved these changes
Apr 30, 2026
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.
I am working on running tests in parallel in CRC and race detector revealed that the random generator used for trace IDs is not thread-safe. This fixes it, Claude also found one more issue. The first commit refactors tests a bit this was needed because previously it relied on fixed random generator with seed value of 0 now that is not possible.
Commit 1: Fix randString race condition in strc package (355cd27)
Commit 2: Fix echo proxy race condition (759db83)
Complete codebase review findings:
On top of that I noticed this has quite old Go version so upgraded Go version, ran
gobumptool to update deps and also dropped the warning inprepare-source.shI think that turned not to be very useful I will be slowly removing this from all the projects. I introduced it... :-)