-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Queue multiple open connection callbacks #585
Conversation
+1 |
Nope, this will leave connections just hanging on mongodb. The reason it was changed was due to people reopening the connection while the driver was attempting to finished the connection startup leaving operations in mid-flight and connections open on mongodb. just call .close before calling open and it will work as you expect. |
Hi, Christian! Just to make it clear, the patch isn't opening new connections, it reuses one single connection queuing callbacks on attempted re-openings. Thanks, anyway! |
self.serverConfig.connect causes problems there is a reason why I don't allow it. Why would you possibly be reopening the connection ???? |
are you trying to reuse connections across multiple dbs ? |
Christian, We read collections in the same DB from independent modules. The DB object is shared across the modules. Previously, we opened a connection every time we needed to read a collection. Now we have to check if the connection has already been opened or is being opened at the moment, and only then we can use the connection. The proposed patch just moves that logic into the driver. So, in effect, the people who used to reopen the connection while it was in the flight, would do the same (as wrong as they might be), but in fact, they wouldn't be reopening the connection – the proposed patch would only schedule their callback to run once the single connection is opened. |
I think this is better left in user land instead of the driver. |
@aheckmann, you suggest that we should check if the connection is opened or is being opened on each connection? Then, maybe the driver could provide some event, like "open"? |
emitting would be nice: switch (db.state) {
case 'connected':
cb();
break;
case 'connecting':
db.once('open', cb);
break;
case 'disconnected':
db.open(cb);
break;
} |
I'm open to emitting as long as it does not break backwards compatibility. |
One problem with closing before opening is that if you do this, the connection is not closed on close callback. db.open(function(){
console.log('open');
db.close(function(){
console.log('close');
db.open(function(){
console.log('open2');
});
});
}); |
sounds like a separate bug |
this is fixed in master now |
Hello. Is it possible to maintain 2 simultaneous MongoDB connections (on different servers)? When I try to open the second connection, I get the following exception: /home/ec2-user/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:437 Thank you. |
Never mind, I figured it out. I had been using connect instead of createConnection. Thanks anyway. |
Hi!
Since the latest version of node-mongodb-native isn't allowing multiple opened connections, some third-party code might have broken.
This patch provides backwards compatibility. When someone tries to open a connection more than once, his callback will nevertheless be executed, even if the connection is remaining single.
Emission of
open
event is also included for convenient subscription.Thanks!