Repository navigation
Report a shared value locked by its own thread as locked under sync - #1190
Merged
schungx merged 1 commit intoOct 17, 2026
Merged
Conversation
Under `sync`, Dynamic::is_locked returned false for every shared value, on the reasoning that access waits for the RwLock. Under `not(unchecked)` it does not wait indefinitely: locked_read tries a few times and gives up, and type_id()/type_name() then unwrap the None and panic. That always happens when the current thread itself holds the value locked for write, so a method call on a shared variable with a closure argument capturing the same variable (`t.with_arg(|| t + 1)`) panicked while resolving the function, where the same script without `sync` gets ErrorDataRace from ensure_no_data_race. Make is_locked report exactly the case locked_read gives up on, so the existing data-race check covers it under `sync` too. Under `sync` + `unchecked` access blocks rather than gives up, so is_locked stays false. This changes the documented meaning of a public method under `sync`. The regression test needs closures (to share the variable), the dot syntax (the method call) and a checked build, so it is gated on `no_closure`, `no_object` and `unchecked`. Refs rhaiscript#1188 (the panic half).
yuvalrakavy
force-pushed
the
fix-shared-value-is-locked-under-sync
branch
from
October 17, 2026 12:14
fb5211a to
26a13a5
Compare
Contributor
Author
|
NoStdBuild: same nightly change as on #1189 (rust-lang/rust#148413); the harness fix is #1191. |
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.
Split out of #1189 at the maintainer's request. Refs #1188 (the panic half); the abort half is #1189.
Under
sync,Dynamic::is_lockedreturnsfalsefor every shared value, on the reasoning that access waits for theRwLock. Undernot(unchecked)it does not wait indefinitely:locked_readtries a few times and gives up, andtype_id()/type_name()then unwrap theNoneand panic. That always happens when the current thread itself holds the value locked for write:Without
sync, #1161'sensure_no_data_raceturns this intoErrorDataRace. Undersyncit does not, becauseis_lockedsays the value is free; the call goes on toresolve_fn, which hashes each argument'stype_id(), and that read gives up and panics.The change makes
is_lockedundersync(and notunchecked) returntrueexactly whenlocked_readwould give up, so the existing data-race check coverssyncas well. Undersync+uncheckedaccess blocks rather than gives up, sois_lockedstaysfalse.This changes the documented meaning of a public method under
sync(the doc said shared values "are never locked" there), which is why it is its own PR for you to shape. Another option is to keepis_lockedas it is and makeensure_no_data_raceprobelocked_readitself.Test:
test_closures_capturing_locked_method_receiverintests/closures.rs, gated onno_closure(the closure must capture the variable to share it; that was the CI failure on theno_closurerow),no_object(the method-call syntax) andunchecked. Undersyncwithout this change it panics intype_id; with it,ErrorDataRaceunder both feature sets.Checks:
cargo test --features sync,cargo test --test closureswith default features and under theno_closureCI row,cargo +nightly fmt --check. CHANGELOG line under 1.27.0's bug fixes, linking this PR.🤖 Generated with Claude Code