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

Uploading a GridFS Stream with client-level timeout cancels context

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 2.0.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Go Drivers
    • Not Needed
    • 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?

      bucket.UploadFromStream and bucket.UploadFromStreamWithID will pre-maturely cancel a context if a client-level timeout is set since the latter method creates the context and defers cancelation.

      func main() {
      	opts := options.Client().SetTimeout(5 * time.Minute)
      
      	client, err := mongo.Connect(opts)
      	if err != nil {
      		panic(err)
      	}
      
      	defer func() { _ = client.Disconnect(context.Background()) }()
      
      	db := client.Database("test")
      
      	bucket := db.GridFSBucket()
      
      	var data bytes.Buffer
      	for i := 0; i < 1e7; i++ {
      		data.WriteString("some large stuff")
      	}
      
      	_, err = bucket.UploadFromStream(context.Background(), "huge_data", bytes.NewBuffer(data.Bytes()))
      	if err != nil {
      		log.Fatalf("failed to open upload stream: %v", err)
      	}
      }
      

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

      Wrap a client-level timeout at the top of bucket.UploadFromStreamWithID:

      ctx, cancel := csot.WithTimeout(ctx, b.db.client.timeout)
      efer cancel()
      

      The exact Go version used, with patch level:

      go version go1.22.6 darwin/arm64

      The exact version of the Go driver used:

      2.0.0-beta1

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

      Local using drivers evergreen tools:

      Current Mongosh Log ID: 66d0d4e6b992a7feb178097c
      Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.4
      Using MongoDB:          8.1.0-alpha-3239-g1fde384
      Using Mongosh:          2.2.4
      mongosh 2.3.0 is available for download: https://www.mongodb.com/try/download/shell
      

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

      Sonoma 14.5

      Security Vulnerabilities

      NA

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

              Created:
              Updated:
              Resolved: