diff --git a/jstests/sharding/repro-server-62710.js b/jstests/sharding/repro-server-62710.js new file mode 100644 index 00000000000..e6429cd574f --- /dev/null +++ b/jstests/sharding/repro-server-62710.js @@ -0,0 +1,48 @@ +(function() { +"use strict"; + +function getIdleCursors(conn) { + return conn.getDB('admin') + .aggregate([{$currentOp: {idleCursors: true}}, {$match: {type: 'idleCursor'}}]) + .toArray(); +} + +var st = new ShardingTest({shards: 1}); + +const dbName = "test"; +const collName = "foo"; +const ns = dbName + "." + collName; + +const coll = st.s.getCollection(ns); + +assert.commandWorked(coll.insert(Array.from({length: 1000}, _ => ({a: 1})))); + +let curs = coll.find({ + $where: function() { + sleep(1); + return true; + } + }) + .batchSize(2) + .maxTimeMS(100); + +assert.throwsWithCode(() => {curs.itcount()}, ErrorCodes.MaxTimeMSExpired); + +{ + sleep(10 * 1000); + const idleCursors = getIdleCursors(st.shard0); + jsTest.log("After maxTimeMSExpired, shard has idle cursors: " + tojson(idleCursors)); +} + +{ + curs.close(); + sleep(10 * 1000); + const idleCursors = getIdleCursors(st.shard0); + jsTest.log("And event after [mongos']curs.close(), shard still has idle cursors: " + + tojson(idleCursors)); +} + +assert.soon(() => {return getIdleCursors(st.shard0) === 0}); + +st.stop(); +})();