Skip to content

fix: data race in AnalyzeTypeAddr for v0.10.4#531

Merged
goccy merged 1 commit intogoccy:masterfrom
sunadoi:fix/data-race
Jan 25, 2025
Merged

fix: data race in AnalyzeTypeAddr for v0.10.4#531
goccy merged 1 commit intogoccy:masterfrom
sunadoi:fix/data-race

Conversation

@sunadoi
Copy link
Copy Markdown
Contributor

@sunadoi sunadoi commented Jan 1, 2025

fix #529

Issue Description

  • runtime.AnalyzeTypeAddr() writes to a global variable alreadyAnalyzed
  • runtime.AnalyzeTypeAddr() could be called once each from both initDecoder and initEncoder
  • When initDecoder and initEncoder were called simultaneously from different goroutines, it was detected as a data race, causing flaky test failures

Solution

Modified runtime.AnalyzeTypeAddr to use sync.Once instead of a global variable to ensure thread-safe initialization

Verification

Ran tests in my project using the following command:

go test -v -race ./... -count=1

Tests that were flaky in v0.10.4 now pass consistently with the fixed code
(verified with over 50 consecutive successful runs)

@sunadoi
Copy link
Copy Markdown
Contributor Author

sunadoi commented Jan 7, 2025

@goccy
Would you review this PR when you have a moment?

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 71.73913% with 13 lines in your changes missing coverage. Please review.

Project coverage is 76.71%. Comparing base (279389a) to head (48e3341).

❗ 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     

@goccy
Copy link
Copy Markdown
Owner

goccy commented Jan 25, 2025

Thank you for your contribution !
LGTM

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Data races between initDecoder and initEncoder operations

3 participants