[CDRIVER-805] Lost notification in mongoc_topology_request_scan Created: 13/Aug/15  Updated: 19/Oct/16  Resolved: 14/Aug/15

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: 1.2-beta0
Fix Version/s: 1.2-beta1

Type: Bug Priority: Major - P3
Reporter: A. Jesse Jiryu Davis Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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.



 Comments   
Comment by Githook User [ 14/Aug/15 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-805 lost notification in request_scan

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.
Branch: 1.2.0-dev
https://github.com/mongodb/mongo-c-driver/commit/def307306e779274e82705e86d5e74ffe089e620

Generated at Wed Feb 07 21:10:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.