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 a deadlock involving scheduler.all_digests, and add a note. (cherrypick of #11723) #13149

Merged
merged 1 commit into from
Oct 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/rust/engine/src/externs/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,8 +1125,8 @@ fn graph_visualize(
with_scheduler(py, scheduler_ptr, |scheduler| {
with_session(py, session_ptr, |session| {
let path = PathBuf::from(path);
scheduler
.visualize(session, path.as_path())
// NB: See the note on with_scheduler re: allow_threads.
py.allow_threads(|| scheduler.visualize(session, path.as_path()))
.map_err(|e| {
let e = format!("Failed to visualize to {}: {:?}", path.display(), e);
PyErr::new::<exc::Exception, _>(py, (e,))
Expand Down Expand Up @@ -1252,8 +1252,9 @@ fn lease_files_in_graph(
) -> PyUnitResult {
with_scheduler(py, scheduler_ptr, |scheduler| {
with_session(py, session_ptr, |session| {
let digests = scheduler.all_digests(session);
// NB: See the note on with_scheduler re: allow_threads.
py.allow_threads(|| {
let digests = scheduler.all_digests(session);
scheduler
.core
.executor
Expand Down Expand Up @@ -1700,6 +1701,11 @@ where
/// context methods provide immutable references. The remaining types are not intended to be shared
/// between threads, so mutable access is provided.
///
/// TODO: The `Scheduler` and `Session` objects both have lots of internal locks: in general, the GIL
/// should be released (using `py.allow_thread(|| ..)`) before any non-trivial interactions with
/// them. In particular: methods that use the `Graph` should be called outside the GIL. We should
/// make this less error prone: see https://github.com/pantsbuild/pants/issues/11722.
///
fn with_scheduler<F, T>(py: Python, scheduler_ptr: PyScheduler, f: F) -> T
where
F: FnOnce(&Scheduler) -> T,
Expand Down