[GODRIVER-2997] WithTransaction completes despite a context cancelation Created: 26/Sep/23  Updated: 18/Dec/23  Resolved: 09/Oct/23

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 1.12.2

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

Issue Links:
Related
related to GODRIVER-2565 Context cancelation before transactio... Closed
is related to GODRIVER-3060 Investigate updating documentation fo... Closed
Documentation Changes: Not Needed
Documentation Changes Summary:

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?


 Description   

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?



 Comments   
Comment by Githook User [ 08/Nov/23 ]

Author:

{'name': 'Steven Silvester', 'email': 'steven.silvester@ieee.org', 'username': 'blink1073'}

Message: GODRIVER-2997 [master] Prevent cancelable context in txn commit loop (#1421)

Co-authored-by: Preston Vasquez <prestonvasquez@icloud.com>
Branch: release/1.12
https://github.com/mongodb/mongo-go-driver/commit/564d5ef699213473ddd00bcc608a0b398fe0208b

Comment by Githook User [ 10/Oct/23 ]

Author:

{'name': 'Steven Silvester', 'email': 'steven.silvester@ieee.org', 'username': 'blink1073'}

Message: GODRIVER-2997 [master] Prevent cancelable context in txn commit loop (#1421)

Co-authored-by: Preston Vasquez <prestonvasquez@icloud.com>
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/b4f5ef1e38c2ed396f403aee5ea39764286a5628

Comment by Preston Vasquez [ 04/Oct/23 ]

The Go Driver could use a non-cancelable context before the commit loop. This would prevent cancelation after the closure but before the operation completely executes and commits.

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