Skip to content

Conversation

@fs-eire
Copy link
Contributor

@fs-eire fs-eire commented Oct 30, 2025

Description

This change fixes a bug that causes crash on macOS (and also potentially other platforms using libc) at OrtReleaseEnv.

Now we don't let the destructor of OrtEnv to be called if the program exits unexpectedly.

Motivation and Context

Fixes #24579

@fs-eire fs-eire requested review from Copilot and snnn October 30, 2025 00:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the mutex protecting the default logger by converting it from a function-local static (Meyer's Singleton pattern) to a static class member. The mutex is moved from the DefaultLoggerMutex() function to LoggingManager::default_logger_mutex_.

  • Removed the DefaultLoggerMutex() function and replaced it with a static member variable
  • Updated all references to use default_logger_mutex_ instead of DefaultLoggerMutex()
  • Updated the comment in CreateDefaultLogger() to reflect the new name

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
onnxruntime/core/common/logging/logging.cc Replaced function-local static mutex with static class member, updated all usages and comments
include/onnxruntime/core/common/logging/logging.h Added declaration of static mutex member

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fs-eire fs-eire force-pushed the fs-eire/fix-mac-mutex-bug branch 2 times, most recently from 4776c4d to 2134765 Compare October 30, 2025 17:57
@fs-eire fs-eire changed the title Fix logging mutex crash at exit on macOS [node] Fix logging mutex crash at exit on macOS Oct 30, 2025
@fs-eire
Copy link
Contributor Author

fs-eire commented Oct 30, 2025

Updated the PR to use a totally different implementation. Now the latest change only modify nodejs binding to ensure no OrtReleaseEnv is called if onnxruntime DLL is closed.

fix destructor order by using different way to deal with OrtEnv
@fs-eire fs-eire force-pushed the fs-eire/fix-mac-mutex-bug branch from 2134765 to 69c8756 Compare October 31, 2025 00:32
@fs-eire
Copy link
Contributor Author

fs-eire commented Oct 31, 2025

@copilot please re-generate overview based on latest code change and remove the out-of-dated one.

Copy link
Contributor

Copilot AI commented Oct 31, 2025

@fs-eire I've opened a new pull request, #26459, to work on those changes. Once the pull request is ready, I'll request review from you.

@fs-eire fs-eire requested a review from Copilot October 31, 2025 00:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fs-eire fs-eire enabled auto-merge (squash) October 31, 2025 21:55
@fs-eire fs-eire merged commit 310ff93 into main Oct 31, 2025
92 checks passed
@fs-eire fs-eire deleted the fs-eire/fix-mac-mutex-bug branch October 31, 2025 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mutex issue at process exit on MacOS since v1.21.*

3 participants