fix: data race in AnalyzeTypeAddr for v0.10.4#531
Merged
goccy merged 1 commit intogoccy:masterfrom Jan 25, 2025
Merged
Conversation
Contributor
Author
|
@goccy |
|
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #531 +/- ##
==========================================
- Coverage 76.74% 76.71% -0.03%
==========================================
Files 55 55
Lines 18931 18926 -5
==========================================
- Hits 14528 14519 -9
- Misses 3771 3774 +3
- Partials 632 633 +1 |
Owner
|
Thank you for your contribution ! |
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.
fix #529
Issue Description
runtime.AnalyzeTypeAddr()writes to a global variablealreadyAnalyzedruntime.AnalyzeTypeAddr()could be called once each from bothinitDecoderandinitEncoderinitDecoderandinitEncoderwere called simultaneously from different goroutines, it was detected as a data race, causing flaky test failuresSolution
Modified
runtime.AnalyzeTypeAddrto usesync.Onceinstead of a global variable to ensure thread-safe initializationVerification
Ran tests in my project using the following command:
go test -v -race ./... -count=1Tests that were flaky in v0.10.4 now pass consistently with the fixed code
(verified with over 50 consecutive successful runs)