If you try to "killCursors" a pinned cursor on a mongos with auth enabled, you will get a CursorInUse error.
The reason is that during the auth checking codepath, we try to check out the cursor (also here) which can return a CursorInUse error. The sharded kill project is supposed to let killCursor kill the cursor regardless of whether it's in use, so I think we should change this behavior.
Here's a way to reproduce the problem:
var coll = db.c;
coll.drop();
for (var i = 0; i < 10; i++) {
assert.writeOK(coll.insert({_id: i}));
}
var failpointName = "keepCursorPinnedDuringGetMore";
var cleanup;
try {
assert.commandWorked(
db.adminCommand({configureFailPoint: failpointName, mode: "alwaysOn"}));
var cmdRes = db.runCommand({find: coll.getName(), batchSize: 2});
assert.commandWorked(cmdRes);
cursorId = cmdRes.cursor.id;
assert.neq(cursorId, NumberLong(0));
// Pin the cursor during a getMore.
var code = 'db.runCommand({getMore: ' + cursorId.toString() + ', collection: "' +
coll.getName() + '"});';
cleanup = startParallelShell(code);
// Sleep for a long time, so we can assume that the cursor will be pinned.
sleep(5000);
cmdRes = db.runCommand({killCursors: coll.getName(), cursors: [cursorId]});
printjson(cmdRes);
}
finally {
cleanup();
assert.commandWorked(db.adminCommand({configureFailPoint: failpointName, mode: "off"}));
}
We should change the auth check to work so that checking out the cursor isn't necessary.