-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 1.6.0, 1.9.1
-
Component/s: Aggregation, Change Streams
-
None
Summary
ChangeStream::createPipelineOptionsDoc() may return nil and set cs.err if failed.
But the caller ChangeStream::executeOperation() does not handle cs.err != nil condition or nil return.
This may lead to broken $changeStream BSON command, and then get an error from mongo server : "invalid bson type in element with field name 'rsor' in object with unknown _id "
My develop environment is go-driver v1.6.0, and I comfirmed this bug in v1.9.1 and master.
My MongoDB server version is MongoDB 4.0
How to Reproduce
- New a Collection with user-defined bson.registry in a golang project, but the user-defined bson.registry has some bugs to cause transformBsoncoreDocument() failure (Maybe there are other cases to cause this failure)
- Watch a collection in golang project, and restart MongoDB server to trigger change stream resume
- The bson.registry bugs lead to transformBsoncoreDocument() failure in ChangeStream::createPipelineOptionsDoc(), and return nil after set cs.err (Maybe there are other cases that lead to transformBsoncoreDocument() failure)
- ChangeStream::executeOperation() ignores the cs.err, and continue to build a broken pipeline BSON
- The broken pipeline BSON command is sent to MongoDB Server, and get "invalid bson" response
Additional Background
ChangeStream::createPipelineOptionsDoc() error is already handled in ChangeStream::buildPipelineSlice(), see: https://github.com/mongodb/mongo-go-driver/blob/v1.9.1/mongo/change_stream.go#L366-L369
But ChangeStream::executeOperation() don't, see: https://github.com/mongodb/mongo-go-driver/blob/v1.9.1/mongo/change_stream.go#L249