[SERVER-30971] Use of "scope" field in mapReduce triggers BSONObj ownership error Created: 06/Sep/17  Updated: 30/Oct/23  Resolved: 07/Sep/17

Status: Closed
Project: Core Server
Component/s: JavaScript
Affects Version/s: 3.4.8
Fix Version/s: 3.2.17, 3.4.9, 3.5.13

Type: Bug Priority: Critical - P2
Reporter: Spencer Jackson Assignee: Spencer Jackson
Resolution: Fixed Votes: 0
Labels: RF
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Related
is related to SERVER-30875 Add support for a "no-owned bson" mod... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v3.4, v3.2
Sprint: Platforms 2017-09-11
Participants:

 Description   

"scope" allows a user to provide a map of global variables to expose to all JS functions ran during a mapReduce job. However, we do not take an owned copy of the map from the command. If scope contains an object, this triggers the memory protection mechanisms added in SERVER-30875.

MongoDB Enterprise > db.runCommand({mapReduce: "foo", map: function(x) {return emit("hello", 1);}, reduce: function(x) { return 0; }, scope: {x: {x: function() {return 5;}}}, out: "bar"})
{
        "ok" : 0,
        "errmsg" : "Attempt to bind an unowned BSON Object to a JS scope marked as requiring ownership",
        "code" : 2,
        "codeName" : "BadValue"
}



 Comments   
Comment by Spencer Jackson [ 11/Feb/19 ]

Hello grabekm90, can you please create a new SERVER ticket describing the issue that you've encountered? When you file this, it would also be very helpful if you could include the MapReduce that you are performing. Thanks!

Comment by Mateusz Grabowski [ 07/Feb/19 ]

Mongo: 3.4.19

Pymongo 3.4

Still the same problem:

{{OperationFailure: command SON([('mapreduce', u'regon_wrap'), ('map', Code('\n function()

{... }

 \n ', {'userPk': 1873, 'selectedParts': {'a': False, 'e': False, 'i': True, 'n': True, 'p': False, 's': False, 'w': False}})), ... ]) on namespace regon_cloud_db.$cmd failed: MR parallel processing failed: { ok: 0.0, errmsg: "Attempt to bind an unowned BSON Object to a JS scope marked as requiring ownership", code: 2, codeName: "BadValue", $gleStats: { lastOpTime: 

{ ts: Timestamp 1549520696000|1, t: 1 }

, electionId: ObjectId('7fffffff0000000000000001') }

So should I downgrade to mongo 3.4.8 to avoid this problem?

Comment by Githook User [ 20/Sep/17 ]

Author:

{'email': 'spencer.jackson@mongodb.com', 'name': 'Spencer Jackson', 'username': 'spencerjackson'}

Message: SERVER-30971: Own "scope" BSONObj in mapReduce

(cherry picked from commit f668265318237dc75708a20254e695869487d884)
(cherry picked from commit 876ebee8c7dd0e2d992f36a848ff4dc50ee6603e)
Branch: v3.2
https://github.com/mongodb/mongo/commit/191c6c43650c5655a530bdd0228cd4370975416e

Comment by Githook User [ 07/Sep/17 ]

Author:

{'username': 'spencerjackson', 'name': 'Spencer Jackson', 'email': 'spencer.jackson@mongodb.com'}

Message: SERVER-30971: Own "scope" BSONObj in mapReduce

(cherry picked from commit f668265318237dc75708a20254e695869487d884)
Branch: v3.4
https://github.com/mongodb/mongo/commit/876ebee8c7dd0e2d992f36a848ff4dc50ee6603e

Comment by Githook User [ 07/Sep/17 ]

Author:

{'username': 'spencerjackson', 'name': 'Spencer Jackson', 'email': 'spencer.jackson@mongodb.com'}

Message: SERVER-30971: Own "scope" BSONObj in mapReduce
Branch: master
https://github.com/mongodb/mongo/commit/f668265318237dc75708a20254e695869487d884

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