Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-805

Lost notification in mongoc_topology_request_scan

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.2-beta1
    • Affects Version/s: 1.2-beta0
    • Component/s: libmongoc
    • None

      In pooled mode, while the background thread is scanning topology->scanning is true. If the scan is finishing while an application thread requests a scan, that means the current scan hasn't found a suitable server for the application operation and probably won't. The scan should repeat ASAP (after minHeartbeatFrequencyMS), but instead the request is lost and the background thread sleeps the full heartbeatFrequencyMS (default 10 seconds).

      The code is effectively:

      void request_scan () {
          lock (mutex);
          if (!topology->scanning) {
              cond_signal (cond);
          }
          unlock (mutex);
      }
      
      void background_scanner () {
          for (;;) {
              lock (mutex);
              topology->scanning = true;
              unlock (mutex);
      
              scan ();
      
              lock (mutex);
              topology->scanning = false;
              cond_timedwait (cond, heartbeatFrequencyMS);
              unlock (mutex);
              sleep_until_min_heartbeat_frequency_passed ();
          }
      }
      

      The lost notification happens if topology->scanning is about to be set false and mongoc_topology_request_scan checks it. The scan should recur ASAP, but waits 10 seconds instead.

      The solution is to not check if topology-scanning in mongoc_topology_request_scan. Instead, always signal the condition.

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: