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

Incorrect Validation of timeoutMS for Tailable AwaitData Cursors

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.0.1, 1.17.3
    • Affects Version/s: None
    • Component/s: None
    • Go Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Detailed steps to reproduce the problem?

      Concerning tailable awaitData cursors:

      Drivers MUST error if this option is set, timeoutMS is set to a non-zero value, and maxAwaitTimeMS is greater than or equal to timeoutMS.

      There are three collection helpers that can create a tailable awaitData cursor: Collection.Find(), Collection.Aggregate(), and Collection.Watch(). Only Collection.Watch() implements this validation, but does so at the Next() level instead of at cursor construction.

      The following can be used to reproduce the problem:

      package main
      
      import (
      	"context"
      	"fmt"
      	"log"
      	"time"
      
      	"go.mongodb.org/mongo-driver/v2/bson"
      	"go.mongodb.org/mongo-driver/v2/mongo"
      	"go.mongodb.org/mongo-driver/v2/mongo/options"
      )
      
      func main() {
      	client, err := mongo.Connect(options.Client())
      	if err != nil {
      		log.Fatal("failed to connect to server: %v", err)
      	}
      
      	defer func() {
      		if err = client.Disconnect(context.Background()); err != nil {
      			log.Fatal("failed to disconnect client: %v", err)
      		}
      	}()
      
      	// Specify the database and collection
      	db := client.Database("exampleDB")
      	coll := db.Collection("exampleCappedCollection")
      
      	opts := options.Find().SetMaxAwaitTime(10 * time.Second)
      
      	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
      	defer cancel()
      
      	_, err = coll.Find(ctx, bson.D{}, opts)
      	fmt.Printf("expect validation error, got: %v\n", err != nil)
      }
      

      Output:

      expect validation error: false
      

      Definition of done: what must be done to consider the task complete?

      1. Add the above validation to Collection.Find(), Collection.Aggregate(), and Collection.Watch(). See the Java implementation concerning change streams here.
      2. Remove the iterative validation from Collection.Watch()

      The exact Go version used, with patch level:

      go version go1.23.1 darwin/arm64

      The exact version of the Go driver used:

      2.0.0

      Describe how MongoDB is set up. Local vs Hosted, version, topology, load balanced, etc.

      NA

      The operating system and version (e.g. Windows 7, OSX 10.8, ...)

      NA

      Security Vulnerabilities

      NA

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

              Created:
              Updated: