From ce77933297d0e1a9a89c7eab7b8fdd39eb5712e1 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Fri, 7 Feb 2025 00:03:26 -0500 Subject: Move session registration for Rust headless initialization to be immediate This fixes a possible race if another thread can successfully shutdown before the current thread can register its session --- rust/src/headless.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'rust/src') diff --git a/rust/src/headless.rs b/rust/src/headless.rs index 2cc87056..3eb6ee57 100644 --- a/rust/src/headless.rs +++ b/rust/src/headless.rs @@ -302,8 +302,11 @@ impl Session { pub fn new() -> Result { if license_location().is_some() { // We were able to locate a license, continue with initialization. + // Grab the session before initialization to prevent another thread from initializing + // and shutting down before this thread can increment the SESSION_COUNT. + let session = Self::registered_session(); init()?; - Ok(Self::registered_session()) + Ok(session) } else { // There was no license that could be automatically retrieved, you must call [Self::new_with_license]. Err(InitializationError::NoLicenseFound) -- cgit v1.3.1