Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix data conflict when prepending preloads from document meta #379

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

youpy
Copy link
Contributor

@youpy youpy commented Nov 16, 2024

Fix data race due to the concurrent access of shared slice by multiple goroutines.

rel/repository.go

Line 1204 in 6c3495d

query.PreloadQuery = append(meta.preload, query.PreloadQuery...)

The above code prepends meta.preload to query.PreloadQuery. However:

  • If the underlying array (meta.preload's capacity) has enough space, the new slice still references the same underlying array.
  • When multiple goroutines prepend to query.PreloadQuery concurrently, they might end up using the same underlying array, leading to:
    • Overwriting of values by different goroutines.
    • Inconsistent results in query.PreloadQuery, as one goroutine's operation interferes with another's.
    • https://go.dev/play/p/ulUQgeS6EBa

To fix this, clone meta.preload and use it for prepending.

Reproduction example

Copy link

codecov bot commented Nov 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (7ac79bf) to head (32bf325).
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #379   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           35        35           
  Lines         4085      4100   +15     
=========================================
+ Hits          4085      4100   +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

1 participant