[SERVER-12780] findAndModify doesn't honour MaxTimeMS Created: 19/Feb/14  Updated: 18/Mar/14  Resolved: 18/Mar/14

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.5.5
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Ross Lawley Assignee: Victor Hooi
Resolution: Duplicate Votes: 0
Labels: 26qa, maxTimeMS
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-12595 findandmodify not honoring maxTimeMS Closed
Related
Operating System: ALL
Steps To Reproduce:

In the shell

t = db.find_and_modify;
t.drop();
 
// fill db
for(var i=1; i<=10000; i++) {
    t.insert({b:i, c:false, d:0});
}
 
// Ensure we aren't simulating this.
t.getDB().adminCommand({configureFailPoint: "maxTimeAlwaysTimeOut", mode: "off"}).ok;
 
t.find({a:1}).maxTimeMS(1);
// error: { "$err" : "operation exceeded time limit", "code" : 50 }
 
t.findAndModify({query:{a:1}, remove:1, maxTimeMS: 1});
// null
 
// Test again
t.find({a:1}).maxTimeMS(1);
// error: { "$err" : "operation exceeded time limit", "code" : 50 }

Participants:

 Description   

Testing on 2.5.6-pre calling {findAndModify} with {maxTimeMS} can take longer than the set duration. Also when doing an equivalent query in a {find} it throws a {operation exceeded time limit} error.



 Comments   
Comment by Victor Hooi [ 18/Mar/14 ]

This is a duplicate of SERVER-12595.

Just to be sure, I've verified this bug exists in 2.5.5, as well as that it's fixed in 2.6.0-RC1.

Comment by Victor Hooi [ 18/Mar/14 ]

I just tried to reproduce this on 2.6.0-rc1 - appears to be fixed:

$ mongo
MongoDB shell version: 2.6.0-rc1
connecting to: test
Server has startup warnings:
2014-03-18T12:26:16.668+1100 [initandlisten]
2014-03-18T12:26:16.668+1100 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
> t = db.find_and_modify;
test.find_and_modify
> t.drop();
false
> for(var i=1; i<=10000; i++) {
    t.insert({b:i, c:false, d:0});
}...    t.insert({b:i, c:false, d:0});
}...}
WriteResult({ "nInserted" : 1 })
> t.getDB().adminCommand({configureFailPoint: "maxTimeAlwaysTimeOut", mode: "off"}).ok;
0
> t.find({a:1}).maxTimeMS(1);
error: { "$err" : "operation exceeded time limit", "code" : 50 }
> t.findAndModify({query:{a:1}, remove:1, maxTimeMS: 1});
2014-03-18T12:35:25.280+1100 findAndModifyFailed failed: {
        "errmsg" : "exception: operation exceeded time limit",
        "code" : 50,
        "ok" : 0
} at src/mongo/shell/collection.js:563
> t.find({a:1}).maxTimeMS(1);
error: { "$err" : "operation exceeded time limit", "code" : 50 }

So from what I can see - maxTimeMS is working as expected in 2.6.0-rc1.

I also checked 2.5.5 - I can confirm that you get null, not an exception, when you use findAndModify with maxTimeMS with 2.5.5:

$ mongo
MongoDB shell version: 2.5.5
connecting to: test
Server has startup warnings:
2014-03-18T15:19:51.277+1100 [initandlisten]
2014-03-18T15:19:51.277+1100 [initandlisten] ** NOTE: This is a development version (2.5.5) of MongoDB.
2014-03-18T15:19:51.277+1100 [initandlisten] **       Not recommended for production.
2014-03-18T15:19:51.277+1100 [initandlisten]
2014-03-18T15:19:51.277+1100 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2014-03-18T15:19:51.277+1100 [initandlisten]
> t = db.find_and_modify;
test.find_and_modify
> t.drop();
true
> for(var i=1; i<=10000; i++) {
... t.insert({b:i, c:false, d:0});
... }
SingleWriteResult({
        "writeErrors" : [ ],
        "writeConcernErrors" : [ ],
        "nInserted" : 1,
        "nUpserted" : 0,
        "nUpdated" : 0,
        "nModified" : 0,
        "nRemoved" : 0,
        "upserted" : [ ]
})
> t.getDB().adminCommand({configureFailPoint: "maxTimeAlwaysTimeOut", mode: "off"}).ok;
0
> t.find({a:1}).maxTimeMS(1);
error: { "$err" : "operation exceeded time limit", "code" : 50 }
> t.findAndModify({query:{a:1}, remove:1, maxTimeMS: 1});
null
> t.find({a:1}).maxTimeMS(1);
error: { "$err" : "operation exceeded time limit", "code" : 50 }

Also - duplicate of SERVER-12595.

Comment by Eric Milkie [ 19/Feb/14 ]

I'm not sure the shell helper supports that. Did you try running the findAndModify command using runCommand, like in the linked ticket?

Generated at Thu Feb 08 03:29:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.