Skip to content

Commit b034c83

Browse files
committed
NODE-889 Fixed issue where legacy killcursor wire protocol messages would not be sent when APM is enableD
1 parent 3a88709 commit b034c83

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

lib/apm.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ var Instrumentation = function(core, options, callback) {
342342
}
343343

344344
if(cmd.maxTimeMS) command.maxTimeMS = cmd.maxTimeMS;
345-
} else if(x == '_killcursors') {
345+
} else if(x == '_killcursor') {
346346
command = {
347347
killCursors: collection,
348348
cursors: [this.cursorState.cursorId]
@@ -461,6 +461,10 @@ var Instrumentation = function(core, options, callback) {
461461
reply: [{ok:1}]
462462
};
463463

464+
// Apply callback to the list of args
465+
args.push(callback);
466+
// Apply the call
467+
func.apply(this, args);
464468
// Emit the command
465469
return self.emit('succeeded', command)
466470
}

test/functional/apm_tests.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,3 +923,55 @@ exports['Correctly receive the APM events for deleteOne'] = {
923923
});
924924
}
925925
}
926+
927+
exports['Ensure killcursor commands are sent on 3.0 or earlier when APM is enabled'] = {
928+
metadata: { requires: { topology: ['single', 'replicaset'], mongodb: "<=3.0.x" } },
929+
930+
// The actual test we wish to run
931+
test: function(configuration, test) {
932+
var started = [];
933+
var succeeded = [];
934+
var failed = [];
935+
var callbackTriggered = false;
936+
937+
var listener = require('../..').instrument(function(err, instrumentations) {});
938+
var db = configuration.newDbInstance({w:1}, {poolSize:1, auto_reconnect:false});
939+
db.open(function(err, db) {
940+
var admindb = db.admin();
941+
var cursorCountBefore;
942+
var cursorCountAfter;
943+
944+
var collection = db.collection('apm_killcursor_tests');
945+
946+
// make sure collection has records (more than 2)
947+
collection.insertMany([
948+
{a : 1}, {a : 2}, {a : 3}
949+
], function(err, r) {
950+
test.equal(null, err);
951+
952+
admindb.serverStatus(function(err, result) {
953+
test.equal(null, err);
954+
955+
cursorCountBefore = result.cursors.clientCursors_size;
956+
957+
var cursor = collection.find({}).limit(2);
958+
cursor.toArray(function(err, r) {
959+
test.equal(null, err);
960+
cursor.close();
961+
962+
admindb.serverStatus(function(err, result) {
963+
test.equal(null, err);
964+
965+
cursorCountAfter = result.cursors.clientCursors_size;
966+
test.equal(cursorCountBefore, cursorCountAfter);
967+
968+
listener.uninstrument();
969+
db.close();
970+
test.done();
971+
});
972+
});
973+
});
974+
});
975+
});
976+
}
977+
}

0 commit comments

Comments
 (0)