Binding invalidation data race fixes #58924
Merged
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 the data races described in #57457 (comment),
summarized here so it can be included in the commit message. It's difficult to
get either of these to crash reliably without tsan, but it does appear in the
wild from time to time (#57457). I'll add these tests when we get tsan to run
on CI.
Data race on
jl_binding_t.backedges
Guard
jl_binding_t.backedges
with the module's lock, using the same strategywe use for the scanned methods array to use it from
invalidations.jl
, namelytaking the lock once to get the length and then locking every time we get the
ith entry in the array. I'm not yet convinced this will avoid missing
invalidations in all circumstances, but it should avoid deadlocks and data
races.
Data race on
jl_module_t.usings_backedges
jl_get_module_usings_backedges
is still guarded byworld_counter_lock
, butwe needed to take it in
jl_new_module_
.Remove type instability in
invalidate_code_for_globalref!
We hold
world_counter_lock
while runninginvalidate_code_for_globalref!
, sowe need to avoid triggering inference entirely. A typeassert avoids the last
few dynamic calls:
TODO: write guidelines for runtime code written in Julia somewhere in devdocs/locks.