When parsing BSONType::Object elements, the automatically-generated parse method will store a view of BSON in the spec, rather than an owned copy. For example,
document_source_out_gen.cpp
else if (fieldName == kUniqueKeyFieldName) { if (MONGO_unlikely(usedFields[kUniqueKeyBit])) { ctxt.throwDuplicateField(element); } usedFields.set(kUniqueKeyBit); if (MONGO_likely(ctxt.checkAndAssertType(element, Object))) { _uniqueKey = element.Obj(); } }
The spec then contains garbage if the original object used for parsing goes out-of-scope. Since the IDL already holds other owned types (e.g. std::string), we should strive to keep an owned copy of BSON.
I don't think this affects existing users of the IDL, as in most usages the original command object is kept around for the lifetime of the command's execution. However, we'd like to serialize $out with the IDL in SERVER-36187, but our reparse-reserialization tests hit a segmentation violation.
- is depended on by
-
SERVER-36187 Use the IDL to serialize $out
- Closed