transistorsoft / react-native-background-fetch

Periodic callbacks in the background for both IOS and Android
MIT License
1.42k stars 191 forks source link

Background Task crash on iOS #488

Open cip123 opened 1 month ago

cip123 commented 1 month ago

Your Environment

Expected Behavior

Application shouldn't crash

Actual Behavior

Application crashes

Steps to Reproduce

I got this in production from one of the devices, dunno if he did anything special, I assume the app was running in the background.

 if (Platform.OS !== "ios") {
    return;
  }

  // BackgroundFetch event handler.
  const onEvent = async (taskId: string) => {
    const hasInfo = await dispatch(fetchWatchInfo);
    if (hasInfo) {
      try {
        await dispatch(sendWatchInfo());
      } catch (e) {}
    }

    // IMPORTANT:  You must signal to the OS that your task is complete.
    BackgroundFetch.finish(taskId);
  };

  // Timeout callback is executed when your Task has exceeded its allowed running-time.
  // You must stop what you're doing immediately BackgroundFetch.finish(taskId)
  const onTimeout = async (taskId: string) => {
    BackgroundFetch.finish(taskId);
  };

  try {
    // Initialize BackgroundFetch only once when component mounts.
    await BackgroundFetch.configure(
      { minimumFetchInterval: 15 },
      onEvent,
      onTimeout
    );
  } catch (e) {
    // user probably doesn't allow background app refresh
  }
};

Context

Not sure what the user was trying to do.

Debug logs

Thread 6 name:
Thread 6 Crashed:
0   libsystem_platform.dylib        0x00000001e0928f18 _os_unfair_lock_recursive_abort + 36 (lock.c:508)
1   libsystem_platform.dylib        0x00000001e09281ac _os_unfair_lock_lock_slow + 280
2   BackgroundTasks                 0x00000001fbcad66c -[BGTask dealloc] + 36 (BGTask.m:96)
3   libsystem_blocks.dylib          0x00000001e09b5074 _Block_object_dispose + 220 (runtime.cpp:1234)
4   libsystem_blocks.dylib          0x00000001e09b56cc _call_dispose_helpers_excp + 44 (generic_helpers.c:30)
5   libsystem_blocks.dylib          0x00000001e09b535c _Block_release + 300 (runtime.cpp:1006)
6   BackgroundTasks                 0x00000001fbcad400 -[BGTask _unsafe_setTaskCompletedWithSuccess:afterDelay:] + 52 (BGTask.m:55)
7   BackgroundTasks                 0x00000001fbcad60c -[BGTask _setTaskCompletedWithSuccess:actionsIfNotAlreadyCompleted:] + 104 (BGTask.m:88)
8   MyApp                     0x0000000101459a28 -[TSBackgroundFetch finish:] + 556
9   MyApp                     0x0000000100f513ac -[RNBackgroundFetch finish:] + 60 (RNBackgroundFetch.m:118)
10  CoreFoundation                  0x0000000195c7df40 __invoking___ + 144 (:-1)
11  CoreFoundation                  0x0000000195c2f1c8 -[NSInvocation invoke] + 276 (NSForwarding.m:3389)
12  CoreFoundation                  0x0000000195c2ed68 -[NSInvocation invokeWithTarget:] + 60 (NSForwarding.m:3486)
13  MyApp                     0x0000000100fe4e40 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 388 (RCTModuleMethod.mm:584)
14  MyApp                     0x0000000100fe6e90 facebook::react::invokeInner(RCTBridge*, RCTModuleData*, unsigned int, folly::dynamic const&, int, (anonymous namespace)::SchedulingContext) + 456 (RCTNativeModule.mm:197)
15  MyApp                     0x0000000100fe6ae0 facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)::$_0::operator()() const + 68 (RCTNativeModule.mm:114)
16  MyApp                     0x0000000100fe6ae0 invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int) + 112 (RCTNativeModule.mm:105)
17  libdispatch.dylib               0x000000019c9bd7a8 _dispatch_call_block_and_release + 24 (init.c:1518)
18  libdispatch.dylib               0x000000019c9be780 _dispatch_client_callout + 16 (object.m:560)
19  libdispatch.dylib               0x000000019c9996fc _dispatch_lane_serial_drain$VARIANT$armv81 + 600 (queue.c:3885)
20  libdispatch.dylib               0x000000019c99a1b0 _dispatch_lane_invoke$VARIANT$armv81 + 380 (queue.c:3976)
21  libdispatch.dylib               0x000000019c9a3f14 _dispatch_workloop_worker_thread + 608 (queue.c:6507)
22  libsystem_pthread.dylib         0x00000001e09b9bd0 _pthread_wqthread + 284 (pthread.c:2618)
23  libsystem_pthread.dylib         0x00000001e09b9720 start_wqthread + 8 (:-1)
christocracy commented 1 month ago

I got this in production from one of the devices

How often? Is this a one-off thing?

cip123 commented 1 month ago

Yes, it is just a one-off thing; I don't have lots of users, though.

christocracy commented 1 month ago

Let me know if you get more. I don't have any idea how this error was generated.

cip123 commented 1 month ago

OK, thanks.

github-actions[bot] commented 5 days ago

This issue is stale because it has been open for 30 days with no activity.