[GODRIVER-2489] Return error if createPipelineOptionsDoc failed in executeOperation Created: 12/Jul/22  Updated: 28/Oct/23  Resolved: 20/Oct/22

Status: Closed
Project: Go Driver
Component/s: Aggregation, Change Streams
Affects Version/s: 1.6.0, 1.9.1
Fix Version/s: 1.10.1

Type: Bug Priority: Major - P3
Reporter: peng zhenyi Assignee: Preston Vasquez
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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



 Comments   
Comment by Githook User [ 02/Aug/22 ]

Author:

{'name': 'Preston Vasquez', 'email': 'prestonvasquez@icloud.com', 'username': 'prestonvasquez'}

Message: GODRIVER-2489 createPipelineOptionsDoc: return err (#1036)
Branch: release/1.10
https://github.com/mongodb/mongo-go-driver/commit/06579a7711952e6518299e57a77bdb5ebedf6586

Comment by Githook User [ 01/Aug/22 ]

Author:

{'name': 'Preston Vasquez', 'email': 'prestonvasquez@icloud.com', 'username': 'prestonvasquez'}

Message: GODRIVER-2489 Return error if createPipelineOptionsDoc() fails (#1035)

Co-authored-by: Preston Vasquez <prestonvasquez@icloud.com>
Co-authored-by: pengzhenyi <503282373@qq.com>
Co-authored-by: Benjamin Rewis <32186188+benjirewis@users.noreply.github.com>
Branch: release/1.10
https://github.com/mongodb/mongo-go-driver/commit/51ecabd07f0fba6a4bb6a40b4a5430cc0aa27db3

Comment by Esha Bhargava [ 15/Jul/22 ]

pengzhenyi Thank you for reporting this issue. We'll look into it and get back to you.

Comment by peng zhenyi [ 12/Jul/22 ]

The error should be handled in go-driver.

So I create a PullRequest: https://github.com/mongodb/mongo-go-driver/pull/1020

Generated at Thu Feb 08 08:38:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.