wix / react-native-notifications

React Native Notifications
MIT License
3.25k stars 764 forks source link

[Bug - Crash] Getting crash in RNNotificationStore #913

Closed Qwin closed 1 year ago

Qwin commented 2 years ago

Hello everyone, I am seeing this crash in Crashlytics, it's happening sporadically. Not sure why this is happening, just that its happening in (RNNotificationsStore.m:61) and (RNNotificationsStore.m:51).

here is the crash log

BUG IN CLIENT OF LIBDISPATCH: Unbalanced call to dispatch_group_leave()

Crashed: com.apple.main-thread
0  libdispatch.dylib              0x39a80 dispatch_group_leave.cold.1 + 36
1  libdispatch.dylib              0x4878 _dispatch_group_wake + 130
2  App                                   0x36ab74 __69-[RNNotificationsStore completePresentation:withPresentationOptions:]_block_invoke + 61 (RNNotificationsStore.m:61)
3  libdispatch.dylib              0x1e6c _dispatch_call_block_and_release + 32
4  libdispatch.dylib              0x3a30 _dispatch_client_callout + 20
5  libdispatch.dylib              0x11f48 _dispatch_main_queue_drain + 928
6  libdispatch.dylib              0x11b98 _dispatch_main_queue_callback_4CF + 44
7  CoreFoundation                 0x51800 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
8  CoreFoundation                 0xb704 __CFRunLoopRun + 2532
9  CoreFoundation                 0x1ebc8 CFRunLoopRunSpecific + 600
10 GraphicsServices               0x1374 GSEventRunModal + 164
11 UIKitCore                      0x514b58 -[UIApplication _run] + 1100
12 UIKitCore                      0x296090 UIApplicationMain + 364
13 App                    0x4ed4 main + 7 (main.m:7)
14 ???                            0x104b31da4 (Missing)

And it happens here as well, seems to happen when removing key from handler dictionary.

Crashed: com.apple.main-thread
0  libdispatch.dylib              0x39a80 dispatch_group_leave.cold.1 + 36
1  libdispatch.dylib              0x4878 _dispatch_group_wake + 130
2  App                                   0x36aa50 __39-[RNNotificationsStore completeAction:]_block_invoke + 51 (RNNotificationsStore.m:51)
3  libdispatch.dylib              0x1e6c _dispatch_call_block_and_release + 32
4  libdispatch.dylib              0x3a30 _dispatch_client_callout + 20
5  libdispatch.dylib              0x11f48 _dispatch_main_queue_drain + 928
6  libdispatch.dylib              0x11b98 _dispatch_main_queue_callback_4CF + 44
7  CoreFoundation                 0x51800 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
8  CoreFoundation                 0xb704 __CFRunLoopRun + 2532
9  CoreFoundation                 0x1ebc8 CFRunLoopRunSpecific + 600
10 GraphicsServices               0x1374 GSEventRunModal + 164
11 UIKitCore                      0x514b58 -[UIApplication _run] + 1100
12 UIKitCore                      0x296090 UIApplicationMain + 364
13 App                    0x4ed4 main + 7 (main.m:7)
14 ???                            0x1054a5da4 (Missing)
callaars commented 2 years ago

I'm actually having the exact same issue, sporadic crashes on the same lines.

mattwoberts commented 1 year ago

I'm seeing that same issue too - 77 occurences in 2 weeks, across different OS versions and phones. I'm not sure what's happening, or how to recreate it.

-[RNNotificationsStore completePresentation:withPresentationOptions:] RNNotificationsStore.m, line 60

callaars commented 1 year ago

That's the problem with me, I can never catch it in the act but it always happens when calling the completionHandler. I've checked the timing and it shouldn't be timing out as there was 8 seconds in processing which is not enough to have the expiry timer being triggered.

jasontulloch commented 1 year ago

I am also dealing with this issue for IOS, specifically related to the second crash report provided:

RNNotificationsStore completeAction:]_block_invoke + 2394552 (RNNotificationsStore.m:51)

The issue on my end frequently appears the first time a user receives a notification, but after the app crashes the issue seems to go away. Has anyone had any luck solving this?

ibrahimPorgin commented 1 year ago

Same error to me. i used react native 0.63.5 and react native notification 4.3.3 in debug mode ios crash when foreground notification. but it's okay to get notification in the background

do you have any idea?

hstorz commented 1 year ago

I found out when I remove the completion callbacks the crash goes away.

I got the same crash (RNNotificationsStore.m:51) everytime I opened a notification from the background. Foreground notifications had no problems.

The app is deployed to Testflight, with v. 4.3.3 and react-native v. 0.70.5

callaars commented 1 year ago

With me it happens always on background notifications and if I remove the completion callback it still happens.

jasontulloch commented 1 year ago

I found out when I remove the completion callbacks the crash goes away.

I got the same crash (RNNotificationsStore.m:51) everytime I opened a notification from the background. Foreground notifications had no problems.

The app is deployed to Testflight, with v. 4.3.3 and react-native v. 0.70.5

@hstorz removing the completion callback appears to be working on our end as well (when app is running in the background or not), thanks for sharing! Do you know why this resolves the issue? We haven't seen any yet, but have you experienced any other issues after removing the callback?

SethArchambault commented 1 year ago

Just got this when testing, looks like the same thing:

image
brianarpie-forme commented 1 year ago

I was running into this same problem and figured out it was caused by calling the registration methods on Notifications.events() multiple times and then receiving a push notification. In my case, these event listeners were initialized inside a useEffect hook that would re-trigger every time the app was backgrounded and then foregrounded. I solved it by moving the handlers to a useEffect hook without any dependencies.

Example:

useEffect(() => {
  Notifications.events().registerNotificationReceivedForeground(() => { ... });
  ... etc
},[]);
KhimGurung commented 1 year ago

@brianarpie-forme if you need dependencies, you need to remove the subscription when component unmounted to avoid that scenario.

useEffect(() => {
  const notification Notifications.events().registerNotificationReceivedForeground(() => { ... });
  return () => {
     notification.remove();
  }
},[dependencies]);
mark-zacharias commented 1 year ago

Thanks @KhimGurung! I was having issues with the app reloading when I tapped a notification. Every time that happened the events would register again and I'd get many notifications displayed for each one sent. The .remove() fixes that.

Now I just have to figure out why it keeps reloading the app.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

TwistedMinda commented 1 year ago

I was running into this same problem and figured out it was caused by calling the registration methods on Notifications.events() multiple times and then receiving a push notification. In my case, these event listeners were initialized inside a useEffect hook that would re-trigger every time the app was backgrounded and then foregrounded. I solved it by moving the handlers to a useEffect hook without any dependencies.

Example:

useEffect(() => {
  Notifications.events().registerNotificationReceivedForeground(() => { ... });
  ... etc
},[]);

Perfect, I could reproduce the crash as you mentioned by calling twice without the .remove() and then trying to open a notification. And preventing two calls by using listener.remove() fixed it.

Awesome, thank you so much! I think this issue can be closed as easily reproducible and fixable

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] commented 1 year ago

The issue has been closed for inactivity.