[CXX-845] Retry query in the case of network error Created: 16/Feb/16  Updated: 03/Jun/16  Resolved: 03/Jun/16

Status: Closed
Project: C++ Driver
Component/s: None
Affects Version/s: legacy-1.1.0
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Wan Bachtiar Assignee: DO NOT USE - Backlog - Platform Team
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related

 Description   

While reading from a replica set and the primary node stepped down, the cursor may return a NULL pointer.

Example code (legacy driver 1.1.0) :

mongo::DBClientReplicaSet connection("replicaName", hosts, 0);
    const bool connected = connection.connect();    
 
    for( int i=0; i<1000; ++i)
    {
        mongo::BSONObj query = BSON( "fieldA" << i );
        mongo::Query mQuery = mongo::Query( query );
        mongo::BSONArray bsonTags;
        mQuery.readPref( mongo::ReadPreference_PrimaryPreferred, bsonTags );
        std::auto_ptr<mongo::DBClientCursor> cursor = connection.query( "database.collection",
                                                 mQuery,
                                                 0, 0, 0,
                                                 mongo::QueryOption_SlaveOk, 0 );
        // If there has been an election in the replica set, the cursor could be NULL. 
        if (cursor.get() != NULL){
            while(cursor->more()){
                mongo::BSONObj p = cursor->next();
                std::cout << p.getStringField("fieldB")<< std::endl;
            }
        }
        else {
            std::cout<< "cursor is NULL, handle error" <<std::endl;
        }
    }



 Comments   
Comment by David Golden [ 03/Jun/16 ]

None of the drivers auto-retry queries. The C++11 driver supports the Server Discovery and Monitoring Spec, which does mandate a reconnection attempt in the case of network error, but the legacy driver is not going to implement SDAM. Therefore, I'm closing this as WONTFIX.

Generated at Wed Feb 07 22:00:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.