Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Commit 19e1b0f

Browse files
committed
refactor(client-session): ensure endSession uses primaryPreferred
NODE-1088
1 parent 8362c8c commit 19e1b0f

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

lib/sessions.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

3-
const Binary = require('mongodb-core').BSON.Binary,
3+
const ReadPreference = require('./topologies/read_preference'),
4+
Binary = require('mongodb-core').BSON.Binary,
45
uuidV4 = require('./utils').uuidV4;
56

67
/**
@@ -40,16 +41,22 @@ class ClientSession {
4041
// can be sent to any mongos. When connected to a replica set the
4142
// endSessions command MUST be sent to the primary if the primary
4243
// is available, otherwise it MUST be sent to any available secondary.
44+
// Is it enough to use: ReadPreference.primaryPreferred ?
4345

44-
this.topology.command('admin.$cmd', { endSessions: 1, ids: [this.id] }, err => {
45-
this.hasEnded = true;
46+
this.topology.command(
47+
'admin.$cmd',
48+
{ endSessions: 1, ids: [this.id] },
49+
{ readPreference: ReadPreference.primaryPreferred },
50+
err => {
51+
this.hasEnded = true;
4652

47-
// release the server session back to the pool
48-
this.sessionPool.release(this.serverSession);
53+
// release the server session back to the pool
54+
this.sessionPool.release(this.serverSession);
4955

50-
if (err) return callback(err, null);
51-
callback(null, null);
52-
});
56+
if (err) return callback(err, null);
57+
callback(null, null);
58+
}
59+
);
5360
}
5461
}
5562

0 commit comments

Comments
 (0)