Uploaded image for project: 'Realm Core'
  1. Realm Core
  2. RCORE-457

Committing may miss notifying DB::wait_for_change if process terminated

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Trivial - P5 Trivial - P5
    • None
    • Affects Version/s: None
    • Component/s: None

      As a rule, if a commit happens, all waiters must be notified. It is also OK to wake waiters if a commit doesn't happen, but we must ensure there is never a missed wakeup.

      There seems to be at least a few potential issues here https://github.com/realm/realm-core/blob/2946c7a52449d3b8d038ff03d896b651615b8ad4/src/realm/db.cpp#L2287-L2295

      1. The update of latest_version_number could be torn and needs to be performed atomically. This applies at least to all 64-bit values. Technically it applies to all modifications that need to be crash-safe, but in practice it is more of a problem for values that aren't 1, 2, or 4 bytes wide.
      2. The call to m_new_commit_available.notify_all() needs to happen earlier, at least before the update of latest_version_number. There may also be a related bug inside of InterprocessCondVar, but I will file a separate ticket for that (#4174 / RCORE-458)
      3. We may need to protect earlier inside the critical section, right before a commit is guaranteed to happen. We must hold the m_controlmutext continuously at least from before we notify until after we update latest_version_number to ensure there are no missed wakeups (or wakeups that see the old version and go back to sleep).

            Assignee:
            Unassigned Unassigned
            Reporter:
            mathias@mongodb.com Mathias Stearn
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: