Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-1597

iOS v10.20.0-beta.2 Flexible sync: subscriptions.update crashes after token expiry

      How frequently does the bug occur?

      All the time

      Description

      Initialising realm subscriptions with flexible sync on iOS results in a crash. This crash only occurs roughly 30 mins after initially logging in (surely due to token expiration?). running refreshCustomData() before updating subscriptions fixes the issue, however this function requires internet access which could brick an offline app.

      Stacktrace & log output

      Unable to find source-code formatter for language: shell. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      OS Version: iOS 15.3.1 (19D52)
      Report Version: 104
      
      Exception Type: EXC_BAD_ACCESS (SIGBUS)
      Exception Codes: BUS_NOOP
      Crashed Thread: 7
      
      Application Specific Information:
      ZTUM >
      Attempted to dereference null pointer.
      
      Thread 7 Crashed:
      0   app   0x2030f16dc   realm::sync::Session::on_new_flx_sync_subscription
      1   app   0x2030424a0   realm::util::UniqueFunction<T>::make_impl<T>::SpecificImpl::call
      2   app   0x2030424a0   realm::util::UniqueFunction<T>::make_impl<T>::SpecificImpl::call
      3   app   0x203132720   realm::sync::MutableSubscriptionSet::commit
      4   app   0x202f10ae0   realm::js::SubscriptionSetClass<T>::update
      5   app   0x202f10774   realm::js::wrap<T>
      

      Can you reproduce the bug?

      Yes, always

      Reproduction Steps

      const initialise = async () => {
        const appConfig = {
          id: '<app id>',
          timeout: 10000,
        };
        const app = new Realm.App(appConfig);
        let user = app.currentUser;
        if (!user || user?.state !== 'active') {
          const credentials = Realm.Credentials.anonymous();
          user = await app.logIn(credentials);
        }
        // await app.currentUser?.refreshCustomData();      <-- This line fixes the null pointer issue but requires internet
        const realm = new Realm({
          schema: [...],
          sync: {
            user: app.currentUser,
            flexible: true,
          },
        });
        realm.subscriptions.update(mutableSubscriptions => {
          realm.schema.forEach(schema => {
            mutableSubscriptions.add(
              realm.objects(schema.name).filtered('userId = $0', user!.id),
              {
                name: schema.name,
              },
            );
          });
        });
      }
      

      Version

      v10.20.0-beta.2 Hermes

      What SDK flavour are you using?

      MongoDB Realm (i.e. Sync, auth, functions)

      Are you using encryption?

      No, not using encryption

      Platform OS and version(s)

      iOS 15.3.1

      Build environment

      Release Mode

      Cocoapods version

      1.11.2

            Assignee:
            tom.duncalf@mongodb.com Tom Duncalf (Inactive)
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: