Skip to content

Commit ce77933

Browse files
committed
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
1 parent 47ef9cd commit ce77933

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

rust/src/headless.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,11 @@ impl Session {
302302
pub fn new() -> Result<Self, InitializationError> {
303303
if license_location().is_some() {
304304
// We were able to locate a license, continue with initialization.
305+
// Grab the session before initialization to prevent another thread from initializing
306+
// and shutting down before this thread can increment the SESSION_COUNT.
307+
let session = Self::registered_session();
305308
init()?;
306-
Ok(Self::registered_session())
309+
Ok(session)
307310
} else {
308311
// There was no license that could be automatically retrieved, you must call [Self::new_with_license].
309312
Err(InitializationError::NoLicenseFound)

0 commit comments

Comments
 (0)