Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Build] Xcode unit tests fail with libc++abi: terminating due to uncaught exception of type onnxruntime::OnnxRuntimeException: #23259

Open
iOSDevD opened this issue Jan 6, 2025 · 1 comment
Labels
build build issues; typically submitted using template platform:mobile issues related to ONNX Runtime mobile; typically submitted using template

Comments

@iOSDevD
Copy link

iOSDevD commented Jan 6, 2025

Describe the issue

When the unit tests are executed it fails with below exception.

libc++abi: terminating due to uncaught exception of type onnxruntime::OnnxRuntimeException: core/session/ort_env.cc:90 static void OrtEnv::Release(OrtEnv *) env_ptr == p_instance_.get() was false.

Urgency

No response

Target platform

iOS

Build script

  • Open Xcode
  • Create a sample unit tests
  • Run the unit tests
  • After the test completes it will crash with the OnnxRuntimeException

If we simply run the code on simulator all works fine, but fails only with unit tests.

Error / output

libc++abi: terminating due to uncaught exception of type onnxruntime::OnnxRuntimeException: core/session/ort_env.cc:90 static void OrtEnv::Release(OrtEnv *) env_ptr == p_instance_.get() was false.

TestFramework is the name of the XCFramework.

 thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 2.2
  * frame #0: 0x00000001802ae3b4 libc++abi.dylib`__cxa_throw
    frame #1: 0x00000001257b6028 `OrtEnv::Release(OrtEnv*) + 268
    frame #2: 0x00000001257aa500 TestFramework`OrtApis::ReleaseEnv(OrtEnv*) + 12
    frame #3: 0x00000001256c7af8 TestFramework`Ort::Env::~Env() + 40
    frame #4: 0x000000018014d0b8 libsystem_c.dylib`__cxa_finalize_ranges + 424
    frame #5: 0x000000018014d44c libsystem_c.dylib`exit + 28
    frame #6: 0x0000000101923fa4 XCTestCore`_XCTestMain + 136
    frame #7: 0x0000000100eccd28 xctest`static xctesttool.xctest.main() -> () + 428
    frame #8: 0x0000000100ecce20 xctest`static xctesttool.xctest.$main() -> () + 12
    frame #9: 0x0000000100ecce34 xctest`main + 12
    frame #10: 0x0000000101215410 dyld_sim`start_sim + 20
    frame #11: 0x0000000100f56274 dyld`start + 2840

Visual Studio Version

No response

GCC / Compiler Version

No response

@iOSDevD iOSDevD added the build build issues; typically submitted using template label Jan 6, 2025
@github-actions github-actions bot added the platform:mobile issues related to ONNX Runtime mobile; typically submitted using template label Jan 6, 2025
@skottmckay
Copy link
Contributor

skottmckay commented Jan 7, 2025

Looks like you have two OrtEnv instances competing with each other as the one in the call to OrtEnv::Release does not match the one inside that instance.

void OrtEnv::Release(OrtEnv* env_ptr) {
if (!env_ptr) {
return;
}
std::lock_guard<std::mutex> lock(m_);
ORT_ENFORCE(env_ptr == p_instance_.get()); // sanity check
--ref_count_;
if (ref_count_ == 0) {
p_instance_.reset();
}
}

There should be only one OrtEnv, and it should remain valid for the duration of any inference session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build build issues; typically submitted using template platform:mobile issues related to ONNX Runtime mobile; typically submitted using template
Projects
None yet
Development

No branches or pull requests

2 participants