Skip to content

Commit

Permalink
Close the socket on authentication error
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgio committed Oct 30, 2020
1 parent b378dca commit 7cabf90
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
### 0.4.4

* Test for text index.
* Fix problem wit "OPENING" state in db. When a socket error happened during opening, the state was't resetted so that any new `db.open()` attempt failed.
* Closing a db when the connection socket was null threw error.
* Changed the way the socket error is thrown on `db.open()`: All errors detected are collected.
1) If after all the attempts the master connection is not on, an error is thrown relative to the the first server tested. This for compatibility reason with the previous way the message was thrown.
2) If the master connection is on, the errors are logged as warning.
* The socket error message has been changed to comprehend also the address of the server, so it is easier to identify the problem.
* If an authentication error occurs, the relative socket is closed.

### 0.4.3

Expand Down
23 changes: 14 additions & 9 deletions lib/src/network/connection_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@ class _ConnectionManager {
if (connection.serverConfig.userName == null) {
_log.fine(() => '$db: ${connection.serverConfig.hostUrl} connected');
} else {
await db
.authenticate(connection.serverConfig.userName,
connection.serverConfig.password,
connection: connection)
.then((v) {
try {
await db.authenticate(
connection.serverConfig.userName, connection.serverConfig.password,
connection: connection);
_log.fine(() => '$db: ${connection.serverConfig.hostUrl} connected');
});
} catch (e) {
if (connection == _masterConnection) {
_masterConnection = null;
}
await connection.close();
rethrow;
}
}
return true;
}
Expand All @@ -66,12 +71,12 @@ class _ConnectionManager {
}
if (connectionErrors.isNotEmpty) {
if (_masterConnection == null) {
var errorString;
for (var error in connectionErrors) {
_log.severe('$error');
errorString = '$error\n';
}
throw MongoDartError(errorString);
// Simply returns the first exception to be more compatible
// with previous error management.
throw connectionErrors.first;
} else {
for (var error in connectionErrors) {
_log.warning('$error');
Expand Down

0 comments on commit 7cabf90

Please sign in to comment.