Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when setting FirestoreCacheSizeUnlimited value in PersistentCacheSettings #11389

Closed
satoshimuraki opened this issue Jun 3, 2023 · 3 comments · Fixed by #11405
Closed
Assignees

Comments

@satoshimuraki
Copy link

Description

This pull request (#11057) has been merged in v10.9.0, but the initializer of FIRPersistentCacheSettings has the following check, and passing FirestoreCacheSizeUnlimited throws an exception and crashes.

if (size.longLongValue < Settings::MinimumCacheSizeBytes) {
     ThrowInvalidArgument("Cache size must be set to at least %s bytes",
                          Settings::MinimumCacheSizeBytes);
}

In the documentation at https://cloud.google.com/firestore/docs/manage-data/enable-offline?hl=en#configure_cache_size there is a code example below.

// The default cache size threshold is 100 MB. Configure "cacheSizeBytes"
// for a different threshold (minimum 1MB) or set to "FirestoreCacheSizeUnlimited"
// to disable clean-up.
let settings = Firestore.firestore().settings
// Set cache size to 1MB
settings.cacheSettings = PersistentCacheSettings(sizeBytes: 1_000_000)
Firestore.firestore().settings = settings

The 1,000,000 bytes specified here is less than Settings::MinimumCacheSizeBytes (1,048,576 bytes), which causes an exception and a crash.

Reproducing the issue

let settings = Firestore.firestore().settings
settings.cacheSettings = PersistentCacheSettings(sizeBytes: NSNumber(value: FirestoreCacheSizeUnlimited))
Firestore.firestore().settings = settings

Firebase SDK Version

10.10.0

Xcode Version

14.3

Installation Method

Swift Package Manager

Firebase Product(s)

Firestore

Targeted Platforms

iOS

Relevant Log Output

2023-06-03 09:21:10.197299+0900 example[8810:736834]  - <AppMeasurement>[I-ACS036001] Analytics screen reporting is disabled. UIViewController transitions will not be logged.
2023-06-03 09:21:10.431050+0900 example[8810:736568] <SKPaymentQueue: 0x282b34460>: No observers found that respond to "paymentQueue:shouldAddStorePayment:forProduct:", will not check for purchase intents
2023-06-03 09:21:10.434977+0900 example[8810:736568] [Firebase/Crashlytics] Version 10.10.0
2023-06-03 09:21:10.465225+0900 example[8810:736840] 10.10.0 - [FirebaseAnalytics][I-ACS023007] Analytics v.10.10.0 started
2023-06-03 09:21:10.465296+0900 example[8810:736840] 10.10.0 - [FirebaseAnalytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/RfcP7r)
2023-06-03 09:21:10.509624+0900 example[8810:736840] 10.10.0 - [FirebaseMessaging][I-FCM001000] FIRMessaging Remote Notifications proxy enabled, will swizzle remote notification receiver handlers. If you'd prefer to manually integrate Firebase Messaging, add "FirebaseAppDelegateProxyEnabled" to your Info.plist, and set it to NO. Follow the instructions at:
https://firebase.google.com/docs/cloud-messaging/ios/client#method_swizzling_in_firebase_messaging
to ensure proper integration.
2023-06-03 09:21:10.512571+0900 example[8810:736568] *** Terminating app due to uncaught exception 'FIRInvalidArgumentException', reason: 'Cache size must be set to at least 1048576 bytes'
*** First throw call stack:
(0x19f43ccb4 0x19855c3d0 0x101cf29c4 0x101cf2540 0x101d2f5a8 0x101d2f548 0x10095e008 0x10095b920 0x10095af7c 0x10095bba0 0x1a17f77e4 0x1a17f6f1c 0x1a17f5ef8 0x1a17f5b70 0x1a184066c 0x1a183f6c4 0x1a183f34c 0x1a7ec30b0 0x10095cce8 0x10095cc60 0x10095dfb0 0x1be9a2dec)
libc++abi: terminating due to uncaught exception of type NSException
(lldb)

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

Expand Package.resolved snippet
{
  "pins" : [
    {
      "identity" : "abseil-cpp-binary",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/google/abseil-cpp-binary.git",
      "state" : {
        "revision" : "bfc0b6f81adc06ce5121eb23f628473638d67c5c",
        "version" : "1.2022062300.0"
      }
    },
    {
      "identity" : "firebase-ios-sdk",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/firebase/firebase-ios-sdk.git",
      "state" : {
        "revision" : "5034479ca0c4f32f299677fb0ba1fe4d3e3e20b4",
        "version" : "10.10.0"
      }
    },
    {
      "identity" : "googleappmeasurement",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/google/GoogleAppMeasurement.git",
      "state" : {
        "revision" : "69f5b8425dd473d2f2475bba7f88f82cd9da0e36",
        "version" : "10.10.0"
      }
    },
    {
      "identity" : "googledatatransport",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/google/GoogleDataTransport.git",
      "state" : {
        "revision" : "5056b15c5acbb90cd214fe4d6138bdf5a740e5a8",
        "version" : "9.2.0"
      }
    },
    {
      "identity" : "googleutilities",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/google/GoogleUtilities.git",
      "state" : {
        "revision" : "871d43135925cde39ef7421d8723ce47edfdcc39",
        "version" : "7.11.1"
      }
    },
    {
      "identity" : "grpc-binary",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/google/grpc-binary.git",
      "state" : {
        "revision" : "2b7656d8ee892cd39db460b1a0d849de618405e6",
        "version" : "1.50.1"
      }
    },
    {
      "identity" : "gtm-session-fetcher",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/google/gtm-session-fetcher.git",
      "state" : {
        "revision" : "d415594121c9e8a4f9d79cecee0965cf35e74dbd",
        "version" : "3.1.1"
      }
    },
    {
      "identity" : "keychainaccess",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/kishikawakatsumi/KeychainAccess.git",
      "state" : {
        "revision" : "84e546727d66f1adc5439debad16270d0fdd04e7",
        "version" : "4.2.2"
      }
    },
    {
      "identity" : "leveldb",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/firebase/leveldb.git",
      "state" : {
        "revision" : "0706abcc6b0bd9cedfbb015ba840e4a780b5159b",
        "version" : "1.22.2"
      }
    },
    {
      "identity" : "nanopb",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/firebase/nanopb.git",
      "state" : {
        "revision" : "819d0a2173aff699fb8c364b6fb906f7cdb1a692",
        "version" : "2.30909.0"
      }
    },
    {
      "identity" : "nantes",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/instacart/Nantes.git",
      "state" : {
        "revision" : "a82b861bc7863b22c798601e28ff2e8ec86ce4ee",
        "version" : "0.1.2"
      }
    },
    {
      "identity" : "promises",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/google/promises.git",
      "state" : {
        "revision" : "46c1e6b5ac09d8f82c991061c659f67e573d425d",
        "version" : "2.1.0"
      }
    },
    {
      "identity" : "reachability.swift",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/ashleymills/Reachability.swift",
      "state" : {
        "revision" : "c01bbdf2d633cf049ae1ed1a68a2020a8bda32e2",
        "version" : "5.1.0"
      }
    },
    {
      "identity" : "realm-core",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/realm/realm-core",
      "state" : {
        "revision" : "36b2df44453ba5e830369c76ab0683799a287605",
        "version" : "13.13.0"
      }
    },
    {
      "identity" : "realm-swift",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/realm/realm-swift.git",
      "state" : {
        "revision" : "9ce8cf2c6cc1a7539e9feb1b5b85da6d20219ff5",
        "version" : "10.40.0"
      }
    },
    {
      "identity" : "swift-protobuf",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/apple/swift-protobuf.git",
      "state" : {
        "revision" : "e1499bc69b9040b29184f7f2996f7bab467c1639",
        "version" : "1.19.0"
      }
    },
    {
      "identity" : "swiftcsv",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/swiftcsv/SwiftCSV.git",
      "state" : {
        "revision" : "96fa14b92e88e0befdbc8bc31c7c2c9594a30060",
        "version" : "0.8.1"
      }
    },
    {
      "identity" : "swiftsoup",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/scinfu/SwiftSoup.git",
      "state" : {
        "revision" : "0e96a20ffd37a515c5c963952d4335c89bed50a6",
        "version" : "2.6.0"
      }
    },
    {
      "identity" : "toast-swift",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/scalessec/Toast-Swift.git",
      "state" : {
        "revision" : "0c9493eeacb102cc614da385cfaaf475379f4ab4",
        "version" : "5.0.1"
      }
    },
    {
      "identity" : "zipfoundation",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/weichsel/ZIPFoundation.git",
      "state" : {
        "revision" : "43ec568034b3731101dbf7670765d671c30f54f3",
        "version" : "0.9.16"
      }
    }
  ],
  "version" : 2
}

If using CocoaPods, the project's Podfile.lock

Expand Podfile.lock snippet
Replace this line with the contents of your Podfile.lock!
@google-oss-bot
Copy link

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@tom-andersen
Copy link
Contributor

Thank you @satoshimuraki for the detailed issue.

We are working to have the MinimumCacheSizeBytes documentation reflect the code (1,048,576 bytes).

I will look at fixing FirestoreCacheSizeUnlimited.

@morganchen12
Copy link
Contributor

The docs are fixed in firebase/snippets-ios#350.

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants