[CXX-71] ScopedDbConnection not being returned to the pool Created: 22/Feb/14  Updated: 10/Apr/14  Resolved: 13/Mar/14

Status: Closed
Project: C++ Driver
Component/s: None
Affects Version/s: legacy-0.0-26compat-2.6.0-rc0
Fix Version/s: legacy-0.0-26compat-2.6.0-rc2

Type: Bug Priority: Minor - P4
Reporter: Pieter Willem Jordaan Assignee: Tyler Brock
Resolution: Done Votes: 0
Labels: ScopedDbConnection, legacy-cxx
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

3.11.0-17-generic #31-Ubuntu SMP Mon Feb 3 21:52:43 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
g++ 4.8.1

mongo 2.5.5 + shared client driver


Issue Links:
Duplicate

 Description   

With a simple snippet like this

	mongo::ScopedDbConnection a("myset/127.0.0.1:27017");
	a.done();

I get repeating warnings in console (of my application) :
2014-02-22T14:22:53.843+0200 [ReplicaSetMonitorWatcher] scoped connection to 127.0.0.1:27017 not being returned to the pool
2014-02-22T14:22:53.843+0200 [ReplicaSetMonitorWatcher] scoped connection to 127.0.0.1:27019 not being returned to the pool

I initially thought it is because my replicaset contains one replica (only primary), but after adding another to the se, I saw the same, except now for both replicas.

What makes this more strange is that the same test with the connection string: "127.0.0.1:27017" (no myset) does not have any warnings.



 Comments   
Comment by Pieter Willem Jordaan [ 13/Mar/14 ]

Hi Tyler

I apologize for my delayed response. I've also witnessed that the problem is gone in the 2.6.0-rc0 version. I am currently using the new tree for the client driver. Thank you

Comment by Tyler Brock [ 13/Mar/14 ]

Hey Pieter,

I'm going to close this issue for now since we haven't heard back from you and mark it as "gone away". We will happily re-open if you have any more questions about this.

Comment by Tyler Brock [ 12/Mar/14 ]

Hey Pieter,

In the future, if you could switch over to using the driver from the new mongo-cxx-driver repository under the legacy branch it would be better as support for building the client driver from the mongodb source code has been removed as of 2.6.0-rc1.

With regards to the problem you were seeing, I was able to reproduce it and see it disappear by creating a simple test program like the one you suggest and running it against a single node replica set:

#include <iostream>
#include "mongo/client/dbclient.h"
 
using namespace std;
using namespace mongo;
 
int main() {
    cout << "Starting... " << endl;
    Status status = client::initialize();
    ScopedDbConnection conn("myset/127.0.0.1:27017");
    conn.done();
    cout << "Done!" << endl;
}

I compiled the program and ran it against the mongoclient shared library from 2.5.5 and 2.6.0-rc0.

2.5.5

$ LD_LIBRARY_PATH=./2.5.5/lib ./a.out
Starting... 
2014-03-12T14:05:44.355-0400 starting new replica set monitor for replica set myset with seeds 127.0.0.1:27017
2014-03-12T14:05:44.355-0400 [ReplicaSetMonitorWatcher] starting
2014-03-12T14:05:44.356-0400 scoped connection to 127.0.0.1:27017 not being returned to the pool
2014-03-12T14:05:44.356-0400 changing hosts to myset/bigbrock:27017 from myset/127.0.0.1:27017
2014-03-12T14:05:44.382-0400 scoped connection to bigbrock:27017 not being returned to the pool
Done!

2.6.0-rc0

$ LD_LIBRARY_PATH=./2.6.0/lib ./a.out
Starting... 
2014-03-12T14:05:50.154-0400 starting new replica set monitor for replica set myset with seeds 127.0.0.1:27017
2014-03-12T14:05:50.154-0400 [ReplicaSetMonitorWatcher] starting
2014-03-12T14:05:50.155-0400 changing hosts to myset/bigbrock:27017 from myset/127.0.0.1:27017
Done! 

The replica set monitor code has changed significantly since 2.5.5. This commit completely re-wrote how the the replica set monitor works: https://github.com/mongodb/mongo/commit/e031dffb83c2a6f9f64a7d055493a8664af997d5

While we did not change the code that prints this message or the behavior of done() we have changed the way the client connects to members of a replica set to get state information (for the better).

Let me know if you would like to dig deeper or if you are satisfied with how it is working currently. I'd be happy to help.

Comment by Pieter Willem Jordaan [ 22/Feb/14 ]

It seems fixed in 2.6.0 rc0 for me, though I can't seem to find the commit which fixed it from 2.5.5

Comment by Pieter Willem Jordaan [ 22/Feb/14 ]

More information. Its not explicitly related to using ScopedDbConnection. If I use

server.push_back(mongo::HostAndPort("127.0.0.1:27017"));
mongo::DBClientReplicaSet rs("myset", server);
// Happens slightly earlier (milliseconds to microseconds earlier) if I do this
rs.connect();

The same happens

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