Realm query sometimes results in an empty array - possible bug?

I queried the database, with an open realm directly after the app starts. Sometimes it results in an empty array as a result, and sometimes it results in the correct data. The problem only occurs directly after the startup of the app. In later queries everything functions as expected. Possible bug happening here? What is the correct way to deal with this problem?

Let me show you some code:

Thats my query:


export const loadCategories = () => {
  return new Promise((resolve, reject) => {
    getPublicRealm()
      .then(realm => {
        const categories = realm.objects('Category').sorted('category_id');
        resolve(categories);
      })
      .catch(error => reject(error));
  });
};

And thats how I am opening the realm:

const config = {id: 'my-id', timeout: 10000};

export const getPublicRealm = async () => {
  const app = new Realm.App(config);
  const credentials = Realm.Credentials.function({
    username: DeviceInfo.getUniqueId(),
  });
  const loggedInUser = await app.logIn(credentials);

  const configuration = {
    schema: [CategorySchema],
    sync: {
      user: loggedInUser,
      partitionValue: 'PUBLIC',
      existingRealmFileBehavior: {type: 'openImmediately', timeout: 10000},
    },
  };

  return Realm.open(configuration);
};