Daily recurring "operation canceled" or "error processing request"


I have a prod app using Realm Sync with partitions ("_partition: user=foobar") on a M2 plan for a few months already.
Everything seems to work as expected but the server logs throw an error every day for a specific function.
I have no idea what can cause it because the log doesn’t say much and the function works 99% of the time.

Here are 2 screenshots with the errors I get. Usually it is mostly operation canceled rather than error processing request

Purpose of my function: I have an iOS game app that needs to check if the user did login today or not (in order to give him a daily reward).
So every time the user opens the game, the app runs this Realm backend function and the function will check in DB if there is a document for today. If no document found, it means the user opens for the first time “today” the game and so we save it in DB. And because we don’t want to handle seconds/minutes/hours of the day, we save it as midnight.

And here is the code.

exports = async function() {
  let todayMidnight = new Date();
  let realToday = new Date(todayMidnight.getTime());
  todayMidnight.setHours(0, 0, 0, 0);
  const user = context.user;
  const realmUserId = user.id;
  const identities = user.identities;
  const partition = "user=" + realmUserId;
  const customIdentity = identities.find(identity => identity.provider_type === "custom-function");
  if (customIdentity !== undefined) {
    const collection = context.services.get("mongodb-atlas").db("app").collection("LoginHistory");
    const todaysLoginHistory = await collection.findOne({ _partition: partition, loginDate: todayMidnight });
    if (todaysLoginHistory !== null) {
      // We already logged in today
      return { 
        realDate: realToday, 
        serverMidnight: todayMidnight,
        insert: false
    } else {
      // First time we login today, save it in DB
      const newLoginHistory = {
        _id: new BSON.ObjectId(),
        _partition: partition,
        loginDate: todayMidnight
      const result = await collection.insertOne(newLoginHistory);
      return { 
        realDate: realToday, 
        serverMidnight: todayMidnight,
        insert: true

// And I do the same with Sign-In With Apple identities

The DB scheme is very simple: _id (objectId), _partition (string), loginDate (date)

Hi Jerome,

I had a look at your app and on our end found context canceled errors which usually mean that either the request was canceled on the client side or on our side. Since the cluster tier is M2 it is very likely that this is happening due to cluster restraints where performance is subject to activity of other clusters sharing the resources. This also makes it difficult to troubleshoot issues as the metric diagnostics are limited on a shared cluster.

Our recommendation for production apps is to have a minimum of M10 cluster tier.
Please try upgrading the cluster. Note that you’ll have to follow this procedure to terminate Realm sync when upgrading from a shared cluster to dedicated tier.


1 Like

Hello Mansoor_Omar,

Thank you for your answer.
I think that Realm Sync or Mongo documentation can maybe mention the potential lack of reliability of M2/M5 clusters.
I guess we will upgrade to M10 in the near future and hope the errors will go away. Just need to prepare the client side for a downtime.

Hi Jerome,

No worries, regarding documentation the minimum tier is mentioned here:


1 Like