Binary too big Realm Sync

Environment

Language: C#


Nuget Version: 10.15.1


Server Type: M2

When I the data is synced, the android app crashes and following error is printed in console.

[libc] /buildbot/src/android/ndk-r25-release/toolchain/llvm-project/libcxx/../../../toolchain/llvm-project/libcxxabi/src/abort_message.cpp:72: abort_message: assertion "terminating with uncaught exception of type realm::LogicError: Binary too big
[libc] Exception backtrace:
[libc] <backtrace not supported on this platform>" failed

Hi, as the message says you’re trying to insert something that is too big. What kind of data are you trying to store?

1 Like

Thanks for reply,
I am not uploading anything when this error occurs.
It occurs when I subscribe to the topic

Mmmm. This is strange and doesn’t ring any bell.
Could you show us some code? There should be at least

  1. the creation of the configuration
  2. the opening of the realm
  3. and the part where you believe this error occurs

Thanks

1 Like

Creation of Configuration and Opening of Realm:

 public async Task<Realm> GetDbInstanceAsync()
        {
            if (_realmApp != null && _realmApp.CurrentUser != null)
            {
                if (_flexibleSyncConfiguration == null)
                {
                    _flexibleSyncConfiguration = new FlexibleSyncConfiguration(_realmApp.CurrentUser);
                    Realm.Compact(_flexibleSyncConfiguration);
                }

                Realm realm = null ;

                // The async call below will only return once sync has run. If we have no internet, it won't return!
                // Therefore, use the async call when we have no database file.
                if (!File.Exists(_flexibleSyncConfiguration.DatabasePath))
                    realm = await Realm.GetInstanceAsync(_flexibleSyncConfiguration);
                else
                    realm = Realm.GetInstance(_flexibleSyncConfiguration);

                return realm;
            }

            return null;
        }

And the part where the error is occurring is where the subscription is made:

public async Task SetupBasicSubscriptionsAsync()
{
try
{
if (_dbService == null)
{
_dbService = Ioc.Default.GetService();
}
var realm = await _dbService.GetDbInstanceAsync();//_dbService.GetDbInstance();
if (realm != null)
{
string id = _dbService.GetRealmApp().CurrentUser.Id;

                //Check if subscriptions are already been subscribed or not.
                var userSubscriptionName = "user_id";
                var userSubscription = realm.Subscriptions.FirstOrDefault(x => x.Name == userSubscriptionName);
                var shouldSubscribeForUser = userSubscription == null;

                var chatsterSubscriptionName = "all_chatsters";
                var chatstersSubscription = realm.Subscriptions.FirstOrDefault(x => x.Name == chatsterSubscriptionName);
                var shouldSubscribeForChatsters = chatstersSubscription == null;

                var conversationsSubscriptionName = "conversations";
                var conversationsSubscription = realm.Subscriptions.FirstOrDefault(x => x.Name == conversationsSubscriptionName);
                var shouldSubscribeForConversations = conversationsSubscription == null;

                var conversationPrefSubscriptionName = "conversationsPrefs";
                var conversationPrefSubscription = realm.Subscriptions.FirstOrDefault(x => x.Name == conversationPrefSubscriptionName);
                var shouldSubscribeForConversationPref = conversationPrefSubscription == null;

                var contactEntrySubscriptionName = "contactEntries";
                var contactEntriesSubscription = realm.Subscriptions.FirstOrDefault(x => x.Name == contactEntrySubscriptionName);
                var shouldSubscribeForContactEntries = contactEntriesSubscription == null;

                var timelineSharedSubscriptionName = "timelinesShared";
                var timelineSharedSubscription = realm.Subscriptions.FirstOrDefault(x => x.Name == timelineSharedSubscriptionName);
                var shouldSubscribeForTimelineShared = timelineSharedSubscription == null;

                var selfTimelineSubscriptionName = "selfTimelines";
                var selfTimelineSubscription = realm.Subscriptions.FirstOrDefault(x => x.Name == selfTimelineSubscriptionName);
                var shouldSubscribeForSelfTimeline = selfTimelineSubscription == null;

                if (shouldSubscribeForUser || shouldSubscribeForChatsters || shouldSubscribeForConversations || shouldSubscribeForConversationPref || shouldSubscribeForContactEntries || shouldSubscribeForTimelineShared || shouldSubscribeForSelfTimeline)
                {
                    realm.Subscriptions.Update(() =>
                    {
                        try
                        {
                            if (shouldSubscribeForUser)
                            {
                                var queryUsers = realm.All<User>().Where(o => o.Id == id);
                                realm.Subscriptions.Add(queryUsers, new SubscriptionOptions()
                                {
                                    Name = userSubscriptionName,
                                    UpdateExisting = true
                                });
                            }
                            //If I Comment out this block, app starts working
                            if (shouldSubscribeForChatsters)// This Subscription is causing the crash
                            {
                                var queryChatster = realm.All<Chatster>();//.Where(o => o.UserName != "");
                                realm.Subscriptions.Add(queryChatster, new SubscriptionOptions()
                                {
                                    Name = "all_chatsters",
                                    UpdateExisting = true
                                });
                            }

                            if (shouldSubscribeForConversations)
                            {
                                var queryConversation = realm.All<Conversation>().Where(o => o.AuthorID == id);
                                realm.Subscriptions.Add(queryConversation, new SubscriptionOptions()
                                {
                                //Name = "conversation",
                                    Name = "conversations",
                                    UpdateExisting = true
                                });
                            }

                            if (shouldSubscribeForConversationPref)
                            {
                                var queryConversation = realm.All<ConversationPreferences>().Where(o => o.AuthorID == id);
                                realm.Subscriptions.Add(queryConversation, new SubscriptionOptions()
                                {
                                //Name = "conversation",
                                    Name = "conversationsPrefs",
                                    UpdateExisting = true
                                });
                            }

                            if (shouldSubscribeForContactEntries)
                            {
                                var queryConversation = realm.All<ContactEntry>().Where(o => o.AuthorID == id);
                                realm.Subscriptions.Add(queryConversation, new SubscriptionOptions()
                                {
                                //Name = "conversation",
                                    Name = "contactEntries",
                                    UpdateExisting = true
                                });
                            }

                            if (shouldSubscribeForTimelineShared)
                            {
                                var querySharedTimeline = realm.All<TimelineShared>().Where(o => o.AuthorID == id);
                                realm.Subscriptions.Add(querySharedTimeline, new SubscriptionOptions()
                                {
                                    Name = "timelinesShared",
                                    UpdateExisting = true
                                });
                            }

                            if (shouldSubscribeForSelfTimeline)
                            {
                                var querySelfTimeline = realm.All<Timeline>().Where(o => o.AuthorID == id);
                                realm.Subscriptions.Add(querySelfTimeline, new SubscriptionOptions()
                                {
                                    Name = "selfTimelines",
                                    UpdateExisting = true
                                });
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    });

                    await realm.Subscriptions.WaitForSynchronizationAsync();
                }
                if(shouldSubscribeForUser)
                    NotificationsService.GetInstance().NotifySyncCompleted(objectType: ObjectType.User);
                NotificationsService.GetInstance().NotifySyncCompleted(objectType: ObjectType.Chatster);
                NotificationsService.GetInstance().NotifySyncCompleted(objectType: ObjectType.ConversationPrefs);
                NotificationsService.GetInstance().NotifySyncCompleted(objectType: ObjectType.ContactEntry);
                NotificationsService.GetInstance().NotifySyncCompleted(objectType: ObjectType.Timeline);
                NotificationsService.GetInstance().NotifySyncCompleted(objectType: ObjectType.TimelineShared);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
    }

And Another thing I noticed is that the Chatster collection size is more that 16MB as following.
image

and I am subscribing to the whole collection.

Hi @Ahmad_Pasha , can you show use how is your schema defined on the app?

@papafe Sorry for late reply.

@papafe I would also like to add that, when I changed the subscriptions method to subscribing one-by-one it started working.
So from this behavior, I guess there is a limit to how much data we can subscribe to in a single subscription?

And also,

Hoping you could tell me if there is any limit to the number of subscriptions you can have at one time?

@papafe Here is the schema for that collection

{
  "bsonType": "object",
  "properties": {
    "_id": {
      "bsonType": "objectId"
    },
    "avatarImage": {
      "bsonType": "object",
      "properties": {
        "_id": {
          "bsonType": "string"
        },
        "date": {
          "bsonType": "date"
        },
        "picture": {
          "bsonType": "binData"
        },
        "thumbNail": {
          "bsonType": "binData"
        }
      },
      "required": [
        "_id",
        "date"
      ],
      "title": "Photo"
    },
    "displayName": {
      "bsonType": "string"
    },
    "lastSeenAt": {
      "bsonType": "date"
    },
    "presence": {
      "bsonType": "string"
    },
    "userName": {
      "bsonType": "string"
    }
  },
  "required": [
    "_id",
    "presence",
    "userName"
  ],
  "title": "Chatster"
}

@Ahmad_Pasha there shouldn’t be any limit to the number of subscriptions you can have.

Regarding your problem it would be really useful to see the stack trace, but unfortunately there is an issue with Android regarding producing stack traces. Would it be possible for you to try to run the project on iOS/MacOS and get the stack trace?

@papafe thanks for reply,
I would not be able to get MacOS/iOS stack trace.

@Ahmad_Pasha No worries.
I will produce a special nuget for you with debug enabled, so we should be able to get more logging.

Ok I will wait @papafe .
Thanks alot

Sorry for the delay, it took some time for the build.
You can use package with version 10.15.1-pr-3029.526 from our night builds (instructions here).
Let me know how it goes

@papafe Thanks for response.
Sorry, I would check the new nuget package in the next week,
cause of an unexpected task which needs immediate attention.