Skip to content

Crash while invalidating URLSession in [RCNConfigFetch recreateNetworkSession] #15087

Open
@iressler

Description

@iressler

Description

This is similar to #14449, if not the exact same issue, however we're still seeing this after upgrading to 11.9.0. We're seeing that the app crashes in Firebase [RCNConfigFetch recreateNetworkSession] while invalidating it's URLSession.

Thread 14 Crashed:
0   libobjc.A.dylib               	0x0000000193a95678 objc_retain_x8 + 16
1   libsystem_blocks.dylib        	0x0000000220aa69d4 <deduplicated_symbol> + 48
2   libsystem_blocks.dylib        	0x0000000220aa67c0 HelperBase<GenericInline>::copyBlock(Block_layout*, Block_layout*) + 108 (runtime.cpp:381)
3   libsystem_blocks.dylib        	0x0000000220aa6460 _call_copy_helpers_excp + 60 (generic_helpers.c:20)
4   libsystem_blocks.dylib        	0x0000000220aa6404 _Block_copy + 412 (runtime.cpp:920)
5   libdispatch.dylib             	0x000000019e4a5a70 _dispatch_Block_copy + 32 (init.c:1563)
6   libdispatch.dylib             	0x000000019e4ab92c dispatch_async + 56 (queue.c:944)
7   CFNetwork                     	0x0000000197b520d8 -[NSURLSession invalidateAndCancel] + 164 (Session.mm:881)
8   Nyx                           	0x000000010103cbd8 -[RCNConfigFetch recreateNetworkSession] + 28
9   Nyx                           	0x0000000101033f2c -[FIRRemoteConfig configSettings] + 240
10  Nyx                           	0x00000001012f6e1c -[RNFBConfigModule getConstantsForApp:] + 176
11  Nyx                           	0x00000001012f6d28 -[RNFBConfigModule resultWithConstants:firebaseApp:] + 104
12  Nyx                           	0x00000001012f5910 __40-[RNFBConfigModule ensureInitialized:::]_block_invoke + 104
13  Nyx                           	0x0000000101031298 __58-[FIRRemoteConfig ensureInitializedWithCompletionHandler:]_block_invoke + 208
14  libdispatch.dylib             	0x000000019e4a5aac _dispatch_call_block_and_release + 32 (init.c:1575)
15  libdispatch.dylib             	0x000000019e4bf584 _dispatch_client_callout + 16 (client_callout.mm:85)
16  libdispatch.dylib             	0x000000019e4dbe84 <deduplicated_symbol> + 32 (:-1)
17  libdispatch.dylib             	0x000000019e4b7f24 _dispatch_root_queue_drain + 736 (queue.c:7342)
18  libdispatch.dylib             	0x000000019e4b854c _dispatch_worker_thread2 + 156 (queue.c:7410)
19  libsystem_pthread.dylib       	0x0000000220aad624 _pthread_wqthread + 232 (pthread.c:2709)
20  libsystem_pthread.dylib       	0x0000000220aaa9f8 start_wqthread + 8 (:-1)

FirebaseCrash.txt

I spent some time investigating this but couldn't come up with a solid reason for the crash. My best guess is that our app is triggering a race condition with RCNConfigFetch's fetchSession where multiple threads are affecting the fetchSession at once but only 1 thread is shown in the crash since the first has already returned by the time of the crash. It's been a decade since I've really written Objective-C, however iirc the change in #14450 of adding atomic doesn't actually provide thread safety, despite the name, which could explain the race condition.

Reproducing the issue

We haven't been able to reproduce it locally so the only information we have is:

  1. The crash logs.
  2. Our logs show the crash happens seconds after app launch/foreground.

Firebase SDK Version

11.9.0

Xcode Version

16.4

Installation Method

CocoaPods

Firebase Product(s)

Firestore, Remote Config, Analytics, Authentication

Targeted Platforms

iOS

Relevant Log Output

We haven't been able to reproduce locally to collect logs.

If using Swift Package Manager, the project's Package.resolved

No response

If using CocoaPods, the project's Podfile.lock

Our Podfile.lock is large and I don't want to share it all, so here are all of the firebase packages, and I can provide more information if necessary.
  - Firebase/Analytics (11.10.0):
    - Firebase/Core
  - Firebase/Auth (11.10.0):
    - Firebase/CoreOnly
    - FirebaseAuth (~> 11.10.0)
  - Firebase/Core (11.10.0):
    - Firebase/CoreOnly
    - FirebaseAnalytics (~> 11.10.0)
  - Firebase/CoreOnly (11.10.0):
    - FirebaseCore (~> 11.10.0)
  - Firebase/Firestore (11.10.0):
    - Firebase/CoreOnly
    - FirebaseFirestore (~> 11.10.0)
  - Firebase/RemoteConfig (11.10.0):
    - Firebase/CoreOnly
    - FirebaseRemoteConfig (~> 11.10.0)
  - FirebaseABTesting (11.10.0):
    - FirebaseCore (~> 11.10.0)
  - FirebaseAnalytics (11.10.0):
    - FirebaseAnalytics/AdIdSupport (= 11.10.0)
    - FirebaseCore (~> 11.10.0)
    - FirebaseInstallations (~> 11.0)
    - GoogleUtilities/AppDelegateSwizzler (~> 8.0)
    - GoogleUtilities/MethodSwizzler (~> 8.0)
    - GoogleUtilities/Network (~> 8.0)
    - "GoogleUtilities/NSData+zlib (~> 8.0)"
    - nanopb (~> 3.30910.0)
  - FirebaseAnalytics/AdIdSupport (11.10.0):
    - FirebaseCore (~> 11.10.0)
    - FirebaseInstallations (~> 11.0)
    - GoogleAppMeasurement (= 11.10.0)
    - GoogleUtilities/AppDelegateSwizzler (~> 8.0)
    - GoogleUtilities/MethodSwizzler (~> 8.0)
    - GoogleUtilities/Network (~> 8.0)
    - "GoogleUtilities/NSData+zlib (~> 8.0)"
    - nanopb (~> 3.30910.0)
  - FirebaseAppCheckInterop (11.10.0)
  - FirebaseAuth (11.10.0):
    - FirebaseAppCheckInterop (~> 11.0)
    - FirebaseAuthInterop (~> 11.0)
    - FirebaseCore (~> 11.10.0)
    - FirebaseCoreExtension (~> 11.10.0)
    - GoogleUtilities/AppDelegateSwizzler (~> 8.0)
    - GoogleUtilities/Environment (~> 8.0)
    - GTMSessionFetcher/Core (< 5.0, >= 3.4)
    - RecaptchaInterop (~> 101.0)
  - FirebaseAuthInterop (11.10.0)
  - FirebaseCore (11.10.0):
    - FirebaseCoreInternal (~> 11.10.0)
    - GoogleUtilities/Environment (~> 8.0)
    - GoogleUtilities/Logger (~> 8.0)
  - FirebaseCoreExtension (11.10.0):
    - FirebaseCore (~> 11.10.0)
  - FirebaseCoreInternal (11.10.0):
    - "GoogleUtilities/NSData+zlib (~> 8.0)"
  - FirebaseFirestore (11.10.0):
    - FirebaseCore (~> 11.10.0)
    - FirebaseCoreExtension (~> 11.10.0)
    - FirebaseFirestoreInternal (= 11.10.0)
    - FirebaseSharedSwift (~> 11.0)
  - FirebaseFirestoreInternal (11.10.0):
    - abseil/algorithm (~> 1.20240722.0)
    - abseil/base (~> 1.20240722.0)
    - abseil/container/flat_hash_map (~> 1.20240722.0)
    - abseil/memory (~> 1.20240722.0)
    - abseil/meta (~> 1.20240722.0)
    - abseil/strings/strings (~> 1.20240722.0)
    - abseil/time (~> 1.20240722.0)
    - abseil/types (~> 1.20240722.0)
    - FirebaseAppCheckInterop (~> 11.0)
    - FirebaseCore (~> 11.10.0)
    - "gRPC-C++ (~> 1.69.0)"
    - gRPC-Core (~> 1.69.0)
    - leveldb-library (~> 1.22)
    - nanopb (~> 3.30910.0)
  - FirebaseInstallations (11.10.0):
    - FirebaseCore (~> 11.10.0)
    - GoogleUtilities/Environment (~> 8.0)
    - GoogleUtilities/UserDefaults (~> 8.0)
    - PromisesObjC (~> 2.4)
  - FirebaseRemoteConfig (11.10.0):
    - FirebaseABTesting (~> 11.0)
    - FirebaseCore (~> 11.10.0)
    - FirebaseInstallations (~> 11.0)
    - FirebaseRemoteConfigInterop (~> 11.0)
    - FirebaseSharedSwift (~> 11.0)
    - GoogleUtilities/Environment (~> 8.0)
    - "GoogleUtilities/NSData+zlib (~> 8.0)"
  - FirebaseRemoteConfigInterop (11.10.0)
  - FirebaseSharedSwift (11.10.0)
```yml - RNFBAnalytics (21.12.2): - Firebase/Analytics (= 11.10.0) - React-Core - RNFBApp - RNFBApp (21.12.2): - Firebase/CoreOnly (= 11.10.0) - React-Core - RNFBAuth (21.12.2): - Firebase/Auth (= 11.10.0) - React-Core - RNFBApp - RNFBFirestore (21.12.2): - Firebase/Firestore (= 11.10.0) - React-Core - RNFBApp - RNFBRemoteConfig (21.12.2): - Firebase/RemoteConfig (= 11.10.0) - React-Core - RNFBApp ```

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions