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

WithTransaction completes despite a context cancelation

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.12.2
    • Affects Version/s: None
    • Component/s: None
    • None
    • 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?

      When running Session.WithTransaction, the BAAS team are seeing data being committed to the database despite a context cancelation.

      The BAAS team is issuing the transaction with the code here: https://github.com/rukumar333/baas/blob/BAAS-24930/realm/sync/server/transactionbroker/registry.go#L414

      The error being returned by the WithTransaction is

      context canceled
      

      The BAAS team uses this fork of the Go Driver in production: https://github.com/mongodb-forks/mongo-go-driver/tree/release/v1.10.7-baas

      Edit:

      Pairing with rushil.kumar@mongodb.com , we can re-create the issue by adding the following code above the "CommitLoop" on either the BAAS fork or the v1 Go Driver branch:

      		ctx, cancel := context.WithCancel(ctx)
      		go func() {
      			fmt.Println("timer started")
      			timer := time.NewTimer(time.Duration(10 * time.Millisecond))
      
      			select {
      			case <-timer.C:
      				fmt.Println("cancel")
      				cancel()
      			}
      		}() 

      This will result in errors such as the following:

      canceled while checking out a connection from connection pool: context canceled; total connections: 0, maxPoolSize: 100, idle connections: 0, wait duration: 250ns 

      The Go Driver documentation for Session.WithTransaction notes that you should not use the method with a cancelable context:

      Because this method must succeed to ensure that server-side resources are properly cleaned up, context deadlines and cancellations will not be respected during this call.

      Open question for triage: Is this a Go Driver bug?

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

              Created:
              Updated:
              Resolved: