[GODRIVER-2565] Context cancelation before transaction commit does not abort Created: 30/Sep/22  Updated: 28/Oct/23  Resolved: 31/Oct/22

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: 1.10.2
Fix Version/s: 1.11.0, 1.10.4

Type: Bug Priority: Major - P3
Reporter: Benji Rewis (Inactive) Assignee: Benji Rewis (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File canceled_test.go    
Issue Links:
Problem/Incident
Related
related to DRIVERS-2471 Run abortTransaction when commitTrans... Backlog
is related to GODRIVER-2997 WithTransaction completes despite a c... Closed
Documentation Changes: Not Needed

 Description   

The title of this ticket is my best guess at what's happening in the following situation . (This came from this slack conversation). See the attached test; occasionally, the test will loop continuously in the second transaction as the first transaction has not properly aborted its identical write server-side. I believe this is because we do not run AbortTransaction correctly when CommitTransaction encounters a context cancelation, but I'm not exactly sure. This requires further investigation and even if the aforementioned theory is correct, we need a more consistent regression test.



 Comments   
Comment by Benji Rewis (Inactive) [ 31/Oct/22 ]

We now call AbortTranasction if the context has errored right before the CommitLoop in WithTransaction. This should help reduce the possibility that transactions are left open server-side when the context errors in WithtTransaction.

Note that if the context errors after the new check and before commitTransaction is actually sent to the server, the transaction will still be left open server-side.

Comment by Githook User [ 31/Oct/22 ]

Author:

{'name': 'Benjamin Rewis', 'email': '32186188+benjirewis@users.noreply.github.com', 'username': 'benjirewis'}

Message: GODRIVER-2565 Abort transaction before CommitLoop if context errored. (#1101)
Branch: release/1.10
https://github.com/mongodb/mongo-go-driver/commit/2855941f871b17048a35b1ac97dc8e11fc61b9da

Comment by Githook User [ 31/Oct/22 ]

Author:

{'name': 'Benjamin Rewis', 'email': '32186188+benjirewis@users.noreply.github.com', 'username': 'benjirewis'}

Message: GODRIVER-2565 Abort transaction before CommitLoop if context errored. (#1101)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/edfc51c61d587862ecb913026813b2dfba85cc90

Comment by Benji Rewis (Inactive) [ 26/Oct/22 ]

https://github.com/mongodb/mongo-go-driver/pull/1101

Comment by Benji Rewis (Inactive) [ 13/Oct/22 ]

Apologies for the delay in response. I can repro the issue and I believe it’s happening because we never run AbortTransaction when CommitTransaction fails in WithTransaction (whether due to timeout or anything else). This is the specified behavior for all drivers, but is a little strange when we know the CommitTransaction call will fail due to something like a canceled context. Opened DRIVERS-2471 to consider a cross-drivers change. In the meantime, I may add a context error check right before CommitTransaction in WithTransaction here, but I think there could still be a context error during CommitTransaction that would cause the transaction to remain open on the server...

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