[SERVER-23169] group failed : Command failed with error 139: 'Failure to enumerate object' Created: 16/Mar/16  Updated: 08/Jan/24  Resolved: 28/Mar/16

Status: Closed
Project: Core Server
Component/s: JavaScript, Querying
Affects Version/s: 3.2.3
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Zhang Youdong Assignee: Jonathan Reams
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-23191 Group command needs to make a copy of... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

db.coll.insert({_id: 1, user: {id: 1016, name: "jack"}})
db.coll.insert({_id: 2, user: {id: 1017, name: "rose"}})
 
db.getCollection("coll").group({
    key:{'user.id':1},
 
reduce:function(doc,value){
    value.user = doc.user; 
    value.order_count++;
    return value;
},
initial:{
order_count:0,user:0
},
finalize:function(res){
}
})  

Sprint: Platforms 12 (04/01/16)
Participants:

 Description   

group failed : Command failed with error 139: 'Failure to enumerate object'

3.2 not work, but 3.0 works



 Comments   
Comment by Ramon Fernandez Marina [ 28/Mar/16 ]

I understand that the fix for SERVER-23191 addresses this ticket as well, so marking it as a duplicate.

Comment by Zhang Youdong [ 18/Mar/16 ]

~jason.carey, thank you for your reply, expecting it to be fiexed ASAP.

Comment by Mira Carey [ 17/Mar/16 ]

zyd_com,

The group statement could and should work in 3.2, it's absolutely a bug that it isn't working today.

There was an optimization added when we migrated from V8 to SpiderMonkey to try and save on copies of some objects. The idea was that we would pass pointers to bson data, rather than owned copies, in some situations to Javascript. We have guards internally to make sure that those unowned pointers aren't dereferenced, but it's still breaking your legitimate use case. That situation is described in the linked server ticket.

Regards,
Jason

Comment by Zhang Youdong [ 17/Mar/16 ]

Thanks for your reply, but I still have a question.

1. the group statement can work in MongoDB-3.0, I want to know if it's caused by change of the javascript engine?(V8 to spidermonkey)

2. when all the docments have the same user.id fields, group can also work.

 db.coll.insert({_id: 1, user: {id: 1016, name: "jack"}})
db.coll.insert({_id: 2, user: {id: 1016, name: "rose"}})
 
db.getCollection("coll").group({
    key:{'user.id':1},
 
reduce:function(doc,value){
    value.user = doc.user; 
    value.order_count++;
    return value;
},
initial:{
order_count:0,user:0
},
finalize:function(res){
}
})  

Comment by Mira Carey [ 16/Mar/16 ]

zyd_com,

It appears that the problem is showing up in the value.user = doc.user assignment. The assignment we make there relies on the doc object having an extended lifetime, and it appears that we're violating that constraint.

Replacing your reproducer with:

db.coll.insert({_id: 1, user: {id: 1016, name: "jack"}})
db.coll.insert({_id: 2, user: {id: 1017, name: "rose"}})
 
db.getCollection("coll").group({
    key:{'user.id':1},
 
reduce:function(doc,value){
    value.user = Object.extend(value.user, doc.user, true);  // note the deep copy 
    value.order_count++;
    return value;
},
initial:{
order_count:0,user:0
},
finalize:function(res){
}
})  

No longer fails for me.

I'll file a ticket with the underlying issue and link it back to this one.

Thanks for your bug report,
Jason

Comment by Ramon Fernandez Marina [ 16/Mar/16 ]

Thanks for the clear reproducer zyd_com, I can reproduce the change in behavior and we're investigating.

Cheers,
Ramón.

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