google / google/GoogleUtilities
Crash Due to Dispatch Group Over-Release with Multiple fetchCompletionHandler Calls
- Dominant language
- Objective-C
- Stars
- 136
- Forks
- 77
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 3
Description
We’ve observed a crash when integrating FirebaseMessaging / GoogleUtilities with the Braze Unity SDK. The issue appears to stem from using a dispatch group in the swizzled AppDelegate: if fetchCompletionHandler is invoked more than once (a behavior not explicitly disallowed by Apple’s docs), an imbalance occurs calling dispatch_group_leave more times than dispatch_group_enter triggers an exception.
## References
* [GoogleUtilities Code (Line 874)](https://github.com/google/GoogleUtilities/blob/ba8e711dc052d88063038ccc60539d00dadcd697/GoogleUtilities/AppDelegateSwizzler/GULAppDelegateSwizzler.m#L874)
* [Braze Unity SDK Issue #107](https://github.com/braze-inc/braze-unity-sdk/issues/107)
Related issues:
1. [Intercom SDK Discussion](https://community.intercom.com/mobile-sdks-24/why-is-the-ios-sdk-crashing-our-app-any-time-a-push-notification-is-received-in-the-background-484)
2. [Firebase iOS SDK Issue #8442](https://github.com/firebase/firebase-ios-sdk/issues/8442)
3. [Braze Unity SDK Issue #10](https://github.com/braze-inc/braze-unity-sdk/issues/10)
## Suggested Resolution
Clarify (via [Apple’s documentation](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/application(_:didreceiveremotenotification:fetchcompletionhandler:)) or internal assumptions) whether fetchCompletionHandler is allowed to be called multiple times, or adjust GoogleUtilities to safely handle multiple invocations. This change would prevent not only the current crash but also avoid hard-to-debug issues with other libraries.
Contributor guide
Assessment
This issue has not been assessed yet.