[SERVER-4525] Disallow access to db object inside of map reduce functions Created: 19/Dec/11  Updated: 06/Dec/22  Resolved: 10/Mar/17

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

Type: Improvement Priority: Major - P3
Reporter: Mathias Stearn Assignee: Backlog - Query Team (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Assigned Teams:
Query
Participants:

 Description   

This is especially important for reduce functions which can be called outside of the db lock but inside of the js lock. This can cause a deadlock since map functions grab the js lock inside of the db lock.



 Comments   
Comment by Tess Avitabile (Inactive) [ 10/Mar/17 ]

This issue has gone away:

> db.c.insert({})
WriteResult({ "nInserted" : 1 })
> db.c.insert({})
WriteResult({ "nInserted" : 1 })
> db.c.mapReduce(function() { emit(0, 0); }, function(k, v) { return db._name; }, {out: "out"})
2017-03-10T16:37:23.741-0500 E QUERY    [main] Error: map reduce failed:{
	"ok" : 0,
	"errmsg" : "ReferenceError: db is not defined :\n_funcs2@:1:29\n",
	"code" : 139,
	"codeName" : "JSInterpreterFailure"
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DBCollection.prototype.mapReduce@src/mongo/shell/collection.js:1411:1
@(shell):1:1
> db.c.mapReduce(function() { emit(0, db._name); }, function(k, v) { return 1; }, {out: "out"})
2017-03-10T16:37:33.018-0500 E QUERY    [main] Error: map reduce failed:{
	"ok" : 0,
	"errmsg" : "ReferenceError: db is not defined :\n_funcs1@:1:25\n",
	"code" : 139,
	"codeName" : "JSInterpreterFailure"
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DBCollection.prototype.mapReduce@src/mongo/shell/collection.js:1411:1
@(shell):1:1

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