From 4f5b7a1cb68c59188bf6efc54436db06a5b5d96e Mon Sep 17 00:00:00 2001 From: Stu Hood Date: Wed, 6 Oct 2021 12:17:58 -0700 Subject: [PATCH] Release the GIL while creating a Session. (#13127) Creating a `Session` accesses the `Graph` to get the number of valid nodes, but when created under the `PySession` wrapper, does so while holding the GIL. Release the GIL in `PySession`. [ci skip-build-wheels] Conflicts: [ci skip-jvm-tests] --- src/rust/engine/src/externs/interface.rs | 11 +++++++---- src/rust/engine/src/scheduler.rs | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/rust/engine/src/externs/interface.rs b/src/rust/engine/src/externs/interface.rs index 872d87352f5..0f14c6a7f4a 100644 --- a/src/rust/engine/src/externs/interface.rs +++ b/src/rust/engine/src/externs/interface.rs @@ -493,14 +493,17 @@ py_class!(class PySession |py| { build_id: String, should_report_workunits: bool ) -> CPyResult { - Self::create_instance(py, Session::new( - scheduler_ptr.scheduler(py), + // NB: Session creation interacts with the Graph, which must not be accessed while the GIL is + // held. + let core = scheduler_ptr.scheduler(py).core.clone(); + let session = py.allow_threads(|| Session::new( + core, should_record_zipkin_spans, should_render_ui, build_id, should_report_workunits, - ) - ) + )); + Self::create_instance(py, session) } }); diff --git a/src/rust/engine/src/scheduler.rs b/src/rust/engine/src/scheduler.rs index 46d4e94d5db..6cfd9586582 100644 --- a/src/rust/engine/src/scheduler.rs +++ b/src/rust/engine/src/scheduler.rs @@ -80,7 +80,7 @@ pub struct Session(Arc); impl Session { pub fn new( - scheduler: &Scheduler, + core: Arc, should_record_zipkin_spans: bool, should_render_ui: bool, build_id: String, @@ -94,7 +94,7 @@ impl Session { }; let inner_session = InnerSession { - preceding_graph_size: scheduler.core.graph.len(), + preceding_graph_size: core.graph.len(), roots: Mutex::new(HashMap::new()), display, should_record_zipkin_spans,