summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-02-07 00:03:26 -0500
committerMason Reed <mason@vector35.com>2025-02-07 00:03:26 -0500
commitce77933297d0e1a9a89c7eab7b8fdd39eb5712e1 (patch)
tree52214757552ff7d74178c93d31f9fdd34bf9c11b /rust/src
parent47ef9cd42471dbc4ff85affb3f6747778562a547 (diff)
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
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/headless.rs5
1 files changed, 4 insertions, 1 deletions
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<Self, InitializationError> {
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)