Skip to content

Commit

Permalink
fix(topology): respect the force parameter for topology close
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Oct 10, 2019
1 parent ad21767 commit d6e8936
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/core/sdam/topology.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,15 @@ class Topology extends EventEmitter {
* Close this topology
*/
close(options, callback) {
if (typeof options === 'function') (callback = options), (options = {});
if (typeof options === 'function') {
callback = options;
options = {};
}

if (typeof options === 'boolean') {
options = { force: options };
}

options = options || {};

// clear all existing monitor timers
Expand Down Expand Up @@ -332,7 +340,7 @@ class Topology extends EventEmitter {
// destroy all child servers
let destroyed = 0;
servers.forEach(server =>
destroyServer(server, this, () => {
destroyServer(server, this, options, () => {
destroyed++;
if (destroyed === servers.size) {
// emit an event for close
Expand Down Expand Up @@ -736,10 +744,11 @@ function isWriteCommand(command) {
*
* @param {Server} server
*/
function destroyServer(server, topology, callback) {
function destroyServer(server, topology, options, callback) {
options = options || {};
LOCAL_SERVER_EVENTS.forEach(event => server.removeAllListeners(event));

server.destroy(() => {
server.destroy(options, () => {
topology.emit(
'serverClosed',
new monitoring.ServerClosedEvent(topology.s.id, server.description.address)
Expand Down

0 comments on commit d6e8936

Please sign in to comment.