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 · 2 comments
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 = signal SIGABRT
  * frame #0: 0x0000000102f3d008 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x00000001030a3408 libsystem_pthread.dylib`pthread_kill + 256
    frame #2: 0x000000018016c4ec libsystem_c.dylib`abort + 104
    frame #3: 0x00000001802ac100 libc++abi.dylib`abort_message + 128
    frame #4: 0x000000018029bae8 libc++abi.dylib`demangling_terminate_handler() + 272
    frame #5: 0x000000018006b8bc libobjc.A.dylib`_objc_terminate() + 140
    frame #6: 0x00000001038950fc XCTestCore`_XCTTerminateHandler() + 96
    frame #7: 0x00000001802ab4d8 libc++abi.dylib`std::__terminate(void (*)()) + 12
    frame #8: 0x00000001802ab488 libc++abi.dylib`std::terminate() + 52
    frame #9: 0x00000001280024c8 TestFramework`__clang_call_terminate + 12
    frame #10: 0x00000001280f650c TestFramework`OrtApis::ReleaseEnv(OrtEnv*) + 24
    frame #11: 0x0000000128013af8 TestFramework`Ort::Env::~Env() + 40
    frame #12: 0x000000018014d0b8 libsystem_c.dylib`__cxa_finalize_ranges + 424
    frame #13: 0x000000018014d44c libsystem_c.dylib`exit + 28
    frame #14: 0x00000001038bffa4 XCTestCore`_XCTestMain + 136
    frame #15: 0x0000000102e20d28 xctest`static xctesttool.xctest.main() -> () + 428
    frame #16: 0x0000000102e20e20 xctest`static xctesttool.xctest.$main() -> () + 12
    frame #17: 0x0000000102e20e34 xctest`main + 12
    frame #18: 0x0000000102fd5410 dyld_sim`start_sim + 20
    frame #19: 0x00000001030de274 dyld`start + 2840

Visual Studio Version

No response

GCC / Compiler Version

No response

OnnxRuntime Version

1.13.X

@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.

@iOSDevD
Copy link
Author

iOSDevD commented Jan 17, 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.

onnxruntime/onnxruntime/core/session/ort_env.cc

Lines 87 to 97 in 704523c

void OrtEnv::Release(OrtEnv* env_ptr) {
if (!env_ptr) {
return;
}
std::lock_guardstd::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.

Sorry there was an error in the log, updated the logs. Thank you.

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