Skip to content

Commit 7cabf90

Browse files
author
Giorgio
committed
Close the socket on authentication error
1 parent b378dca commit 7cabf90

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
### 0.4.4
66

77
* Test for text index.
8+
* 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.
9+
* Closing a db when the connection socket was null threw error.
10+
* Changed the way the socket error is thrown on `db.open()`: All errors detected are collected.
11+
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.
12+
2) If the master connection is on, the errors are logged as warning.
13+
* The socket error message has been changed to comprehend also the address of the server, so it is easier to identify the problem.
14+
* If an authentication error occurs, the relative socket is closed.
815

916
### 0.4.3
1017

lib/src/network/connection_manager.dart

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,18 @@ class _ConnectionManager {
4343
if (connection.serverConfig.userName == null) {
4444
_log.fine(() => '$db: ${connection.serverConfig.hostUrl} connected');
4545
} else {
46-
await db
47-
.authenticate(connection.serverConfig.userName,
48-
connection.serverConfig.password,
49-
connection: connection)
50-
.then((v) {
46+
try {
47+
await db.authenticate(
48+
connection.serverConfig.userName, connection.serverConfig.password,
49+
connection: connection);
5150
_log.fine(() => '$db: ${connection.serverConfig.hostUrl} connected');
52-
});
51+
} catch (e) {
52+
if (connection == _masterConnection) {
53+
_masterConnection = null;
54+
}
55+
await connection.close();
56+
rethrow;
57+
}
5358
}
5459
return true;
5560
}
@@ -66,12 +71,12 @@ class _ConnectionManager {
6671
}
6772
if (connectionErrors.isNotEmpty) {
6873
if (_masterConnection == null) {
69-
var errorString;
7074
for (var error in connectionErrors) {
7175
_log.severe('$error');
72-
errorString = '$error\n';
7376
}
74-
throw MongoDartError(errorString);
77+
// Simply returns the first exception to be more compatible
78+
// with previous error management.
79+
throw connectionErrors.first;
7580
} else {
7681
for (var error in connectionErrors) {
7782
_log.warning('$error');

0 commit comments

Comments
 (0)