Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 31, 2025

Fixes crash at OrtReleaseEnv on macOS (and other libc platforms) caused by mutex destruction order issues in the default logger.

Solution: Refactor Node.js binding to use Meyer's Singleton pattern for ORT environment lifecycle, intentionally leaking Ort::Env at program exit to avoid destructor ordering problems.

Implementation:

  • OrtSingletonData: Meyer's Singleton managing global Ort::Env and default Ort::RunOptions via function-local static
  • OrtInstanceData: Per-environment N-API instance data for thread-local constructor references
  • No explicit cleanup: Ort::Env never destroyed, eliminating OrtReleaseEnv call that triggered the crash
// Before: env destroyed at exit, causing mutex crash
std::unique_ptr<Ort::Env> env;  // Destructor calls OrtReleaseEnv

// After: function-local static leaks intentionally
OrtSingletonData::OrtObjects& OrtSingletonData::GetOrCreateOrtObjects(int log_level) {
  static OrtObjects ort_objects(log_level);  // Never destroyed
  return ort_objects;
}

Fixes #24579


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix logging mutex crash at exit on macOS [node] Fix logging mutex crash at exit on macOS Oct 31, 2025
Copilot AI requested a review from fs-eire October 31, 2025 00:40
Copilot finished work on behalf of fs-eire October 31, 2025 00:40
@fs-eire fs-eire closed this Oct 31, 2025
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.

2 participants