Skip to content

Commit cc02f83

Browse files
committed
refactor: store full ismaster on connection until StreamDescription
Storing a local `ServerDescription` is not adequate for the needs of wire protocol determination, in particular when a monitor connection is initially connected. Until then, we will store the full `ismaster` directly on the connection, like we did with the previous connection type.
1 parent 29a4cd6 commit cc02f83

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

lib/cmap/connection.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const MongoError = require('../core/error').MongoError;
66
const MongoNetworkError = require('../core/error').MongoNetworkError;
77
const MongoWriteConcernError = require('../core/error').MongoWriteConcernError;
88
const CommandResult = require('../core/connection/command_result');
9+
const ServerDescription = require('../core/sdam/server_description').ServerDescription;
910
const wp = require('../core/wireprotocol');
1011
const apm = require('../core/connection/apm');
1112
const updateSessionFromResponse = require('../core/sessions').updateSessionFromResponse;
@@ -18,6 +19,7 @@ const kGeneration = Symbol('generation');
1819
const kLastUseTime = Symbol('lastUseTime');
1920
const kClusterTime = Symbol('clusterTime');
2021
const kDescription = Symbol('description');
22+
const kIsMaster = Symbol('ismaster');
2123

2224
class Connection extends EventEmitter {
2325
constructor(stream, options) {
@@ -79,6 +81,10 @@ class Connection extends EventEmitter {
7981
return this[kDescription];
8082
}
8183

84+
get ismaster() {
85+
return this[kIsMaster];
86+
}
87+
8288
// the `connect` method stores the result of the handshake ismaster on the connection
8389
set ismaster(response) {
8490
if (response.compression) {
@@ -93,7 +99,11 @@ class Connection extends EventEmitter {
9399
}
94100
}
95101

96-
this[kDescription] = response;
102+
// TODO: This should be using a `StreamDescription`
103+
this[kDescription] = new ServerDescription(this.address, response);
104+
105+
// TODO: remove this, and only use the `StreamDescription` in the future
106+
this[kIsMaster] = response;
97107
}
98108

99109
get generation() {

lib/core/sdam/monitor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function checkServer(monitor, callback) {
167167
}
168168

169169
monitor[kConnection] = conn;
170-
callback(undefined, conn.description);
170+
callback(undefined, conn.ismaster);
171171
});
172172
}
173173

output

1.19 KB
Binary file not shown.

0 commit comments

Comments
 (0)