Crash when app enter background
#37
0 libc++abi.dylib __cxa_get_exception_ptr +88
1 libc++abi.dylib __cxa_throw +92
2 libc++.1.dylib std::__1::__throw_system_error +92
3 libc++.1.dylib std::__1::__throw_system_error(int, char const*) +32
4 libc++.1.dylib std::__1::mutex::lock() +40
5 MicrosoftCognitiveServicesSpeech GetModuleObject
6 libsystem_c.dylib __cxa_finalize_ranges +480
7 libsystem_c.dylib exit +32
8 BackBoardServices __28-[BKSHIDEventObserver _init]_block_invoke_3 +100
9 BoardServices __31-[BSServiceConnection activate]_block_invoke.182 +124
10 BoardServices __61-[BSXPCServiceConnectionEventHandler _connectionInvalidated:]_block_invoke +196
11 BoardServices BSXPCServiceConnectionExecuteCallOut +240
12 BoardServices -[BSXPCServiceConnectionEventHandler _connectionInvalidated:] +180
13 libdispatch.dylib _dispatch_call_block_and_release +32
14 libdispatch.dylib _dispatch_client_callout +16
15 libdispatch.dylib _dispatch_lane_serial_drain +740
16 libdispatch.dylib _dispatch_lane_invoke +440
17 libdispatch.dylib _dispatch_lane_serial_drain +332
18 libdispatch.dylib _dispatch_lane_invoke +440
19 libdispatch.dylib _dispatch_root_queue_drain_deferred_wlh +292
20 libdispatch.dylib _dispatch_workloop_worker_thread +540
21 libsystem_pthread.dylib _pthread_wqthread +292
22 libsystem_pthread.dylib start_wqthread +8
-
Li Wangbiao 0 Reputation points
@Thanmayi Godithi Hi, just following up on this issue.
The key point is that the crash can happen even when the user does not enter or use Microsoft speech recognition. In that scenario, we do not create SpeechConfig, SpeechRecognizer, PushAudioInputStream, or start continuous recognition. The app only links MicrosoftCognitiveServicesSpeech-iOS 1.47.0.
So this does not look like an active recognizer cleanup issue on our side. Could you please help confirm whether there is any known issue in 1.47.0 where the Speech SDK native module may crash during background transition or teardown just because the framework is linked/loaded?
Also, could you advise which iOS Speech SDK version contains the relevant fix, if this has already been addressed?
This is currently blocking our investigation, so we would appreciate your guidance. Thanks!
Sign in to comment
4 answers
-
Li Wangbiao 0 Reputation points
@Thanmayi Godithi
Hi, just following up on this issue.The key point is that the crash can happen even when the user does not enter or use Microsoft speech recognition. In that scenario, we do not create SpeechConfig, SpeechRecognizer, PushAudioInputStream, or start continuous recognition. The app only links MicrosoftCognitiveServicesSpeech-iOS 1.47.0.
So this does not look like an active recognizer cleanup issue on our side. Could you please help confirm whether there is any known issue in 1.47.0 where the Speech SDK native module may crash during background transition or teardown just because the framework is linked/loaded?
Also, could you advise which iOS Speech SDK version contains the relevant fix, if this has already been addressed?
This is currently blocking our investigation, so we would appreciate your guidance. Thanks!
-
Thanmayi Godithi 10,655 Reputation points • Microsoft External Staff • Moderator
Hey Li, it looks like your app is crashing inside the Speech SDK’s native code when it goes into the background – specifically during a
std::mutex::lock()inGetModuleObject, which usually means the SDK is trying to clean up a static/global object after the C++ runtime has started tearing down. Here are a few things to try:- Make sure you’re explicitly stopping and disposing all Speech SDK objects before your app enters background. • In your AppDelegate (or equivalent), implement applicationDidEnterBackground (or sceneWillResignActive) and do something like: – await recognizer.stopContinuousRecognitionAsync(); – recognizer.close(); – config = null;
- Upgrade to the latest Speech SDK. We’ve fixed a few static-destructor race conditions in recent releases.
- If you’re using any static/singleton wrappers around the SDK, switch to per-instance usage and dispose them cleanly on background.
- As a workaround, you can disable the built-in module unload on exit by holding onto your main
SpeechConfig/SpeechRecognizerinstances until the app fully suspends.
If you’re still seeing the crash, please share:
- The exact Speech SDK version you’re on
- Your OS version/device model
- A short snippet showing how/where you initialize and tear down the recognizer
- Any other background-transition code you have
Hope this points you in the right direction!
-
Li Wangbiao 0 Reputation points
Hi, one important update: this crash also happens when the user has not used Microsoft speech recognition in that session.
In the crash scenario, we do not create SpeechConfig, SpeechRecognizer, PushAudioInputStream, or start continuous recognition. The app only links MicrosoftCognitiveServicesSpeech-iOS through CocoaPods.
Our current version is MicrosoftCognitiveServicesSpeech-iOS 1.47.0.
The crash stack still points to Speech SDK native code, std::mutex::lock() in GetModuleObject, during background transition.
So this does not look like an active recognizer lifecycle cleanup issue on our side. Could you help confirm whether 1.47.0 has any known issue where the native framework/static module object can initialize or tear down just because the framework is linked/loaded, even without creating recognizer instances?
Also, is there a specific iOS fix in 1.48.x / 1.49.x / 1.50.x for this background/static module teardown crash? If yes, which version should we upgrade to for iOS CocoaPods?
-
Thanmayi Godithi 10,655 Reputation points • Microsoft External Staff • Moderator
Hi,
Thank you for the above information. I will look into this and will get back to you shortly.
-
Thanmayi Godithi 10,655 Reputation points • Microsoft External Staff • Moderator
Hi Li,
Thank you for the additional details — that clarification is very important.
Based on what you've described, I agree that this no longer appears to be a recognizer lifecycle cleanup issue in the application layer. The fact that the crash occurs even when no
SpeechConfig,SpeechRecognizer,PushAudioInputStream, or recognition session is ever created suggests that the failure may be occurring during framework initialization or teardown within the native Speech SDK itself rather than in application-managed Speech SDK objects.Looking at the stack trace, the crash is occurring in:
MicrosoftCognitiveServicesSpeech
GetModuleObject
std::__1::mutex::lock()
__cxa_finalize_ranges
exit
which indicates the failure is happening during native runtime cleanup while the process/framework is being torn down, rather than during an active recognition operation. The crash location is consistent with a native module/static-object cleanup path.
At this time, I am not aware of publicly documented release notes that specifically call out a fix for a
GetModuleObject/std::mutex::lock()crash during iOS background transition or static module teardown. The Speech SDK release notes for 1.48.x–1.50.x mention several fixes, but none explicitly reference this scenario.Nevertheless, since you are currently using MicrosoftCognitiveServicesSpeech-iOS 1.47.0, I would strongly recommend validating whether the issue reproduces with the latest available Speech SDK version (currently 1.50.x), as a number of native stability fixes have been included across subsequent releases.
To help determine whether this is an SDK-level issue, could you also share:
- iOS version(s) where the crash is observed
- Whether the Speech SDK is linked as a dynamic framework or static XCFramework
- Whether Crashlytics (or another symbolication tool) consistently shows the same
GetModuleObject→std::mutex::lock()call path - A full symbolicated crash report if available
If the issue can be reproduced on the latest SDK release and still occurs without any Speech SDK object creation, we can engage the Speech SDK engineering team for deeper investigation, as that would indicate the crash may be occurring solely due to framework load/unload behaviour rather than application usage.
Thanks for providing the additional context, and I look forward to your findings.
-
Li Wangbiao 0 Reputation points
Thanks for the detailed explanation.
Here are the details from our side:
- We are currently using MicrosoftCognitiveServicesSpeech-iOS 1.47.0. We will validate the issue again with the latest available Speech SDK version later.
- The crash started appearing on iOS 18.4 and above.
- The Speech SDK is linked as a dynamic framework. We use MicrosoftCognitiveServicesSpeech-iOS via CocoaPods, which integrates MicrosoftCognitiveServicesSpeech.xcframework. The iOS arm64 slice is a Mach-O dynamically linked shared library, and CocoaPods embeds MicrosoftCognitiveServicesSpeech.framework into the app bundle.
- Yes, Crashlytics consistently shows the same call path involving: MicrosoftCognitiveServicesSpeech GetModuleObject std::__1::mutex::lock() __cxa_finalize_ranges exit
- I have attached the full symbolicated crash report for your reference.crash_log.txt
Please help engage the Speech SDK engineering team to investigate this further, especially since the crash can occur even when no Speech SDK objects are created by the app.
Thanks.
Sign in to comment -
-
Li Wangbiao 0 Reputation points
MicrosoftCognitiveServicesSpeech-iOS:1.47.0
-
AI answer
The stack trace shows a
std::__1::mutex::lock()throwingstd::__1::__throw_system_error, which indicates a C++std::system_errorcoming from a mutex operation insideMicrosoftCognitiveServicesSpeech::GetModuleObjectduring process teardown (__cxa_finalize_ranges/exit). This is happening on a background thread when the app is going to background/being torn down.From the available context, the only actionable guidance is to treat this as an unhandled exception/crash coming from a native library and ensure it is captured and diagnosable via a crash-reporting SDK:
- Integrate App Center Crashes (iOS) into the app if not already done, following the iOS getting started guidance referenced in the documentation.
- Ensure the app is run without a debugger attached when reproducing, because the SDK will not forward crash logs while a debugger is attached.
- Once the crash is captured in App Center, use the symbolicated stack trace to confirm the exact call path into
MicrosoftCognitiveServicesSpeechand correlate it with app lifecycle events (e.g., backgrounding, deallocation of speech objects). - If the crash is confirmed to be inside the Microsoft Cognitive Services Speech native library during teardown, open a support ticket with the Speech SDK team including:
- The symbolicated crash log
- SDK version
- Repro steps (especially what happens when the app enters background and how speech objects are created/disposed).
If the app uses App Center Crashes already, the callbacks described in the documentation (
willSendErrorReport,didSucceedSendingErrorReport,didFailSendingErrorReport) can be used to verify that the crash report is successfully sent and to attach any additional diagnostic data (for example, current speech SDK state) viaattachments(with:for:)before the stored crash is uploaded on next launch.
References:
AI-generated content may be incorrect. Read our transparency notes for more information.
