[CXX-316] Handle MongoDB connection string format differently than legacy format Created: 26/Aug/14  Updated: 23/Oct/14  Resolved: 07/Oct/14

Status: Closed
Project: C++ Driver
Component/s: API
Affects Version/s: legacy-1.0.0-rc0
Fix Version/s: legacy-1.0.0-rc1

Type: Improvement Priority: Minor - P4
Reporter: Tyler Brock Assignee: Samantha Ritter (Inactive)
Resolution: Done Votes: 0
Labels: legacy-cxx
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

All


Issue Links:
Depends
depends on CXX-336 Remove Connection Pool Closed

 Description   

ConnectionString::parse currently falls back to allowing an alternate internal mongodb connection format that can be parsed and considered valid by isValid() but do the wrong thing when connecting (which is surprising for the user).

An example of this is the following url:

localhost:1050,localhost:1055,localhost:1056/?replicaSet=rs-83d7523f-16cf-4246-8014-f1a6fa7ec264

It doesn't start with a mongodb:// so it's parsed in classic mode which creates the following observable behavior on the resulting connection string:

  • isValid() returns true
  • getServers() returns: replicaSet=rs-83d7523f-16cf-4246-8014-f1a6fa7ec264:27017 which is essentially the replica set portion
  • getSetName returns: "localhost:1050,localhost:1055,localhost:1056" which is essentially the servers portion
  • connect() fails with: "connect failed to replica set localhost:1050,localhost:1055,localhost:1056/?replicaSet=rs-83d7523f-16cf-4246-8014-f1a6fa7ec264:27017"

I am proposing that we split the functionality by having

  • ConnectionString::parse accept only valid MongoDB connection strings
  • Another parsing function to handle the odd deprecated internal format

We can also probably throw if there is no match in the new function now that we don't support the older version of the api.



 Comments   
Comment by Githook User [ 07/Oct/14 ]

Author:

{u'username': u'samantharitter', u'name': u'Samantha Ritter', u'email': u'samantha.ritter@10gen.com'}

Message: CXX-316 Update Connection String URI Parsing
Branch: legacy
https://github.com/mongodb/mongo-cxx-driver/commit/e3a7573fa73b6fa5c380827b8a5580a6eb5466f0

Comment by Samantha Ritter (Inactive) [ 10/Sep/14 ]

https://github.com/mongodb/mongo-cxx-driver/pull/140

Comment by Tyler Brock [ 27/Aug/14 ]

Hey Samantha. Failure is expected but not encountered, which is why this needs to change.

The code works because it finds a slash in the MongoDB URI. However, the parameters to ConnectionString are flipped. In the proprietary format the set name is on the left and servers on the right, the MongoConnection string has the servers on the left and the params (like set name) on the right so it winds up building a connection string with {{ (?ReplicaSet=XXX)}} as the servers and the server list (member1:port,member2:port...) as the replica set name (when its the list if servers):

string::size_type i = url.find( '/' );
        if ( i != string::npos && i != 0) {
            // replica set
            return ConnectionString( SET , url.substr( i + 1 ) , url.substr( 0 , i ) );
        }

The result is that it appears to work (isValid() returns true) but it builds a connection string with the wrong information and can't connect.

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