Skip to content

Commit 2d607fa

Browse files
committed
refactor: don't authenticate monitoring connections
1 parent 7f3cfba commit 2d607fa

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

lib/core/sdam/monitor.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,29 @@ class Monitor extends EventEmitter {
6161

6262
// TODO: refactor this to pull it directly from the pool, requires new ConnectionPool integration
6363
const addressParts = server.description.address.split(':');
64-
this.connectOptions = Object.freeze(
65-
Object.assign(
66-
{
67-
id: '<monitor>',
68-
host: addressParts[0],
69-
port: parseInt(addressParts[1], 10),
70-
bson: server.s.bson,
71-
connectionType: Connection
72-
},
73-
server.s.options,
74-
this.options,
75-
76-
// force BSON serialization options
77-
{
78-
raw: false,
79-
promoteLongs: true,
80-
promoteValues: true,
81-
promoteBuffers: true
82-
}
83-
)
64+
const connectOptions = Object.assign(
65+
{
66+
id: '<monitor>',
67+
host: addressParts[0],
68+
port: parseInt(addressParts[1], 10),
69+
bson: server.s.bson,
70+
connectionType: Connection
71+
},
72+
server.s.options,
73+
this.options,
74+
75+
// force BSON serialization options
76+
{
77+
raw: false,
78+
promoteLongs: true,
79+
promoteValues: true,
80+
promoteBuffers: true
81+
}
8482
);
83+
84+
// ensure no authentication is used for monitoring
85+
delete connectOptions.credentials;
86+
this.connectOptions = Object.freeze(connectOptions);
8587
}
8688

8789
connect() {

lib/core/sdam/topology.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class Topology extends EventEmitter {
276276

277277
translateReadPreference(options);
278278
const readPreference = options.readPreference || ReadPreference.primary;
279-
this.selectServer(readPreferenceServerSelector(readPreference), options, err => {
279+
const connectHandler = err => {
280280
if (err) {
281281
this.close();
282282

@@ -294,7 +294,15 @@ class Topology extends EventEmitter {
294294
this.emit('connect', this);
295295

296296
if (typeof callback === 'function') callback(err, this);
297-
});
297+
};
298+
299+
// TODO: NODE-2471
300+
if (this.s.credentials) {
301+
this.command('admin.$cmd', { ping: 1 }, { readPreference }, connectHandler);
302+
return;
303+
}
304+
305+
this.selectServer(readPreferenceServerSelector(readPreference), options, connectHandler);
298306
}
299307

300308
/**

0 commit comments

Comments
 (0)