Skip to content
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

Connection pool not working correctly #140

Open
sstinger opened this issue Dec 29, 2018 · 4 comments
Open

Connection pool not working correctly #140

sstinger opened this issue Dec 29, 2018 · 4 comments

Comments

@sstinger
Copy link

If I use new Db.pool with WriteConcern.JOURNALED and one Server of the Cluster is down I get a connection error.
Is this correct or is there an other possibility to connect to a cluster?

new Db("mongodb://127.0.0.1:27017,127.0.0.1:27018,127.0.0.1:27019/test");
This is also not working.

Can't I auto failover to the primary with this lib?

@thosakwe
Copy link
Contributor

thosakwe commented Dec 29, 2018 via email

@sstinger
Copy link
Author

Thx for the quick reply.
I try to connect to a replica set with 3 nodes to auto failover if the Primary goes down and a secondary becomes primary.
In the nodejs driver you can use the mongodb:// url like mongodb://127.0.0.1:27017,127.0.0.1:27018,127.0.0.1:27019/test with all nodes to failover.
Her is the example: https://mongodb.github.io/node-mongodb-native/driver-articles/mongoclient.html
But if I try this with mongo dart driver I get an FormatException:

Unhandled exception:
FormatException: Invalid port (at character 21)
mongodb://127.0.0.1:27017,127.0.0.1:27017/test
                    ^

#0      new _Uri.notSimple.<anonymous closure> (dart:core/uri.dart:1471:11)
#1      int._throwFormatException (dart:core/runtime/libintegers_patch.dart:126:40)
#2      int._parse (dart:core/runtime/libintegers_patch.dart:104:14)
#3      int.parse (dart:core/runtime/libintegers_patch.dart:61:12)
#4      new _Uri.notSimple (dart:core/uri.dart:1470:20)
#5      Uri.parse (dart:core/uri.dart:1012:16)

So I thought I can use the pool function to do that:

library replica_tests;

import 'package:mongo_dart/mongo_dart.dart';
import 'dart:async';
//import 'package:logging/logging.dart';
import 'package:test/test.dart';

const DefaultUri1 = 'mongodb://127.0.0.1:27017';
const DefaultUri2 = 'mongodb://127.0.0.1:27018';
const DefaultUri3 = 'mongodb://127.0.0.1:27019';

Future testCollectionInfoCursor() {
  Db db = new Db.pool([
    "${DefaultUri1}/mongo_dart-test",
    "${DefaultUri2}/mongo_dart-test",
    "${DefaultUri3}/mongo_dart-test"
  ], 'testCollectionInfoCursor');
  DbCollection newColl;
  return db.open(writeConcern: WriteConcern.JOURNALED).then((c) {
    newColl = db.collection("new_collecion");
    return newColl.remove({});
  }).then((v) {
    return newColl.insertAll([
      {"a": 1}
    ]);
  }).then((v) {
    return db.getCollectionInfos({'name': 'new_collecion'});
  }).then((v) {
    expect(v, hasLength(1));
    return db.close();
  });
}

main() {
//  hierarchicalLoggingEnabled = true;
//  Logger.root.level = Level.OFF;
//  new Logger('ConnectionManager').level = Level.ALL;
//  var listener = (LogRecord r) {
//    var name = r.loggerName;
//    if (name.length > 15) {
//      name = name.substring(0, 15);
//    }
//    while (name.length < 15) {
//      name = "$name ";
//    }
//    print("${r.time}: $name: ${r.message}");
//  };
//  Logger.root.onRecord.listen(listener);

  group('DbCollection tests:', () {
    test('testCollectionInfoCursor', testCollectionInfoCursor);
  });
}

If all three nodes are Online and healthie it's working but if one node goes down (no matter which one) I get this Exception:

SocketException: OS Error: Der Remotecomputer hat die Netzwerkverbindung abgelehnt.
, errno = 1225, address = 127.0.0.1, port = 53309

dart:async                                     _Completer.completeError
lib\src\network\connection.dart 78:17          _Connection.connect.<fn>
===== asynchronous gap ===========================
dart:async                                     Future.catchError
lib\src\network\connection.dart 77:8           _Connection.connect
lib\src\network\connection_manager.dart 23:22  _ConnectionManager._connect
===== asynchronous gap ===========================
dart:async                                     Future.forEach
lib\src\network\connection_manager.dart 56:19  _ConnectionManager.open
lib\src\database\db.dart 253:33                Db.open.<fn>
dart:async                                     new Future.sync
lib\src\database\db.dart 240:16                Db.open
test\replica_tests.dart 19:13                  testCollectionInfoCursor

Process finished with exit code 1

How can I alternatively failover in a replica set?

I hope you understand my question and excuse my bad english

@FaisalAbid
Copy link

@thosakwe did you ever find a solution to this? This is a blocker for me right now

@merterkoc
Copy link

I would be glad if you use this package that I have just developed. I continue to develop and have plans to bring a lot of features.
https://pub.dev/packages/mongo_pool
https://github.com/merterkoc/mongo_pool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants