Repository navigation
Conversation
Summary: `PushNotificationIOS.setApplicationIconBadgeNumber` can still hang the main thread long enough to trigger an `0x8badf00d` watchdog kill, even after the switch to `-[UNUserNotificationCenter setBadgeCount:withCompletionHandler:]`. That API takes a completion handler but is not asynchronous to its caller. Inside `-[UNUserNotificationServiceConnection setBadgeCount:forBundleIdentifier:withCompletionHandler:]` it `dispatch_sync`s onto the UserNotifications connection queue. That queue is serial and shared by every UserNotifications call in the process. A synchronous call on another thread, such as reading `UIApplication.applicationIconBadgeNumber`, holds it for a full XPC round trip to `usernotificationsd`. `RCTPushNotificationManager.methodQueue` is the main queue, so a slow daemon reply on any thread becomes a main-thread hang. In the hang reports the stacks look like this: - Main thread: `-[RCTPushNotificationManager setApplicationIconBadgeNumber:]` -> `-[UNUserNotificationCenter setBadgeCount:withCompletionHandler:]` -> `_dispatch_sync_f_slow` / `__DISPATCH_WAIT_FOR_QUEUE__` - Another thread: `-[UIApplication applicationIconBadgeNumber]` -> `-[UNUserNotificationServiceConnection badgeNumberForBundleIdentifier:]` -> `_dispatch_lane_barrier_sync_invoke_and_complete` -> `xpc_connection_send_message_with_reply_sync` This change issues the badge write from a private serial queue. Serial keeps writes in order, so the last write wins. Utility QoS, because nothing waits on the queue. `getApplicationIconBadgeNumber` is unchanged: `UIApplication.applicationIconBadgeNumber` is main-thread-only, and there is no public off-main read API. Changelog: [iOS][Fixed] Fix remaining main-thread watchdog hang in PushNotificationIOS.setApplicationIconBadgeNumber Reviewed By: christophpurrer Differential Revision: D125826470
|
@fkgozali has exported this pull request. If you are a Meta employee, you can view the originating Diff in D125826470. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
PushNotificationIOS.setApplicationIconBadgeNumbercan still hang the main thread long enough to trigger an0x8badf00dwatchdog kill, even after the switch to-[UNUserNotificationCenter setBadgeCount:withCompletionHandler:].That API takes a completion handler but is not asynchronous to its caller. Inside
-[UNUserNotificationServiceConnection setBadgeCount:forBundleIdentifier:withCompletionHandler:]itdispatch_syncs onto the UserNotifications connection queue. That queue is serial and shared by every UserNotifications call in the process. A synchronous call on another thread, such as readingUIApplication.applicationIconBadgeNumber, holds it for a full XPC round trip tousernotificationsd.RCTPushNotificationManager.methodQueueis the main queue, so a slow daemon reply on any thread becomes a main-thread hang.In the hang reports the stacks look like this:
-[RCTPushNotificationManager setApplicationIconBadgeNumber:]->-[UNUserNotificationCenter setBadgeCount:withCompletionHandler:]->_dispatch_sync_f_slow/__DISPATCH_WAIT_FOR_QUEUE__-[UIApplication applicationIconBadgeNumber]->-[UNUserNotificationServiceConnection badgeNumberForBundleIdentifier:]->_dispatch_lane_barrier_sync_invoke_and_complete->xpc_connection_send_message_with_reply_syncThis change issues the badge write from a private serial queue. Serial keeps writes in order, so the last write wins. Utility QoS, because nothing waits on the queue.
getApplicationIconBadgeNumberis unchanged:UIApplication.applicationIconBadgeNumberis main-thread-only, and there is no public off-main read API.Changelog: [iOS][Fixed] Fix remaining main-thread watchdog hang in PushNotificationIOS.setApplicationIconBadgeNumber
Reviewed By: christophpurrer
Differential Revision: D125826470