Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2489

Return error if createPipelineOptionsDoc failed in executeOperation

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.10.1
    • 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

      1. 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)
      2. Watch a collection in golang project, and restart MongoDB server to trigger change stream resume
      3. 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)
      4. ChangeStream::executeOperation() ignores the cs.err, and continue to build a broken pipeline BSON
      5. 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

            Assignee:
            preston.vasquez@mongodb.com Preston Vasquez
            Reporter:
            pengzhenyi peng zhenyi
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: