[SERVER-32395] Make killCursors work against pinned cursors on mongos when auth is enabled Created: 18/Dec/17  Updated: 30/Oct/23  Resolved: 07/Feb/18

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: 3.7.2

Type: Improvement Priority: Major - P3
Reporter: Ian Boros Assignee: Ian Boros
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Query 2018-02-12
Participants:

 Description   

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.



 Comments   
Comment by Githook User [ 07/Feb/18 ]

Author:

{'email': 'ian.boros@10gen.com', 'name': 'Ian Boros'}

Message: SERVER-32395 Make killCursors work against pinned cursors on mongos when auth is enabled
Branch: master
https://github.com/mongodb/mongo/commit/8630f685156c7515c59ce071e59d9d6ec200f2e4

Generated at Thu Feb 08 04:30:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.