Mobile Bytes #2: Terminate and Re-enable Sync and Error Handling in MongoDB Realm

Hello Realm Enthusiasts,

Last week we discussed Schema Changes and the necessity to terminate Sync if Destructive Schema changes are made.

This week we will talk more on Terminating and Re-enabling Sync, errors that can happen while working with Realm, and what can be some proactive ways to handle them.

Terminating and Re-enabling Sync is an expensive and destructive action, but is necessary under specific circumstances like destructive schema changes or upgrading from shared to dedicated tier Atlas Clusters – Check the Terminate Sync section to learn more.

     Note - Please wait 10 minutes after you Terminate Sync, as it takes time to recreate the meta-data. 
      After 10 min, enter the config details and Re-enable Sync again.

The aftermath of this action can lead to the following errors so it is recommended to have a handling mechanism in place before you perform this action.

A. BadClientFileIdentifier or Error Code 208

What it means -The file on the client (on mobile) has gone out of sync with the partition data (Realm) on Atlas or is not available

Or

B. ErrorDivergingHistories

What it means - This is a similar error to above. This means that Sync history on the client file does not match the history on the server partition.

Handling Process - Can be handled by implementing Client-Reset. The client-reset implementation will delete the local realm file, download a fresh copy from the server and then both client and partition will be in Sync. In the event that Client Reset logic is not implemented, this can be handled by reinstalling the app.

Some helpful posts that talks about Client Reset Implementation

Realm Client Reset errorHandler returns NIL session.configuration()

MongoDBEncodingErrors

what causes this - Uploading data that does not conform to schema or uploading deeply nested array data can lead to rejection of writes (for example exceeding the Realm’s nesting limit of 100).

Handling Process - The client schema must conform to the server schema. If you have fields that can have unstructured or different values, it is recommended to use mixed or dictionary field types.

Check Realm Sync Schema Data Consistency for more information.

Some helpful error handling discussions

Transient Errors

  • Invalid Session - naturally caused by auth/refresh tokens being automatically resumed.
  • Internal Server Error - indicates realm issue, resolved by built-in retry logic.

These errors may sometimes appear in your Realm logs but most of the time these are transient and can be ignored. Sync should work after the server reconnects, but if it does not resume after a time, please feel free to post a query on the forum.

The Realm SDKs can be configured to handle errors and generate logs based on severity level. Check Handle and Log Sync Errors section in MongoDB documentation.

I hope the provided information is helpful.

I look forward to some codefight wins from you all :wink:

Please feel free to comment on what errors you came across, how you solved them, and what would you like me to talk about next week.

Happy Realming!

Cheers, :smiley:
Henna

5 Likes