Detailed steps to reproduce the problem?
The CSOT specification requires that timeoutMS from the parent MongoClient be inherited by sessions and applied to transaction operations including withTransaction, commitTransaction, and abortTransaction. Currently, the Go Driver only supports the operation-level analogue.
The following CSOT unified spec test can be used to repro:
go test -run TestUnifiedSpec/client-side-operations-timeout/tests/sessions-inherit-timeoutMS.json ./internal/integration/unified -v
Definition of done: what must be done to consider the task complete?
(1)Session.AbortTransaction and Session.CommitTransaction need to pass the client-level timeoutMS value through the operation
-(2) session.WithTransaction needs to apply client timeout to context, if set:-
ctx, cancel := csot.WithTimeout(ctx, s.client.timeout) defer cancel()
-(3) The [CSOT specifications|] say-
If the callback returns an error and the transaction must be aborted, drivers
MUST refresh the `timeoutMS` value for the `abortTransaction` operation.
The Go Driver is non-compliant with this, relying on legacy [and buggy] behavior that
ignores timeouts and context cancelations while aborting transactions within the
convenience API.
If client-side abort fails, the server has its own transaction timeout
-(transactionLifetimeLimitSeconds, default 60 seconds). The transaction will eventuallybe cleaned up server-side.
The spec rationale explicitly accepts this trade-off:
This can cause the entire withTransaction call to take up to 2*timeoutMS, but it
was decided that this risk is worthwhile given the importance of transaction cleanup.
Suggested fix:
abortCtx, abortCancel := csot.WithTimeout(newBackgroundContext(ctx), timeoutDur) _ = s.AbortTransaction(abortCtx) abortCancel()
WLOG commitTransaction also needs a refresh timeout
(4) The following tests should be removed from the skip-list:
"TestUnifiedSpec/client-side-operations-timeout/tests/sessions-inherit-timeoutMS.json/timeoutMS_applied_to_commitTransaction" "TestUnifiedSpec/client-side-operations-timeout/tests/sessions-inherit-timeoutMS.json/timeoutMS_applied_to_abortTransaction" "TestUnifiedSpec/client-side-operations-timeout/tests/sessions-inherit-timeoutMS.json/timeoutMS_applied_to_withTransaction" "TestUnifiedSpec/client-side-operations-timeout/tests/sessions-override-operation-timeoutMS.json/timeoutMS_applied_to_withTransaction"
- has to be done before
-
GODRIVER-3323 Implement CSOT Prose Tests
-
- Backlog
-
-
GODRIVER-3771 Fix flaky CSOT withTransaction tests
-
- Blocked
-
- is duplicated by
-
GODRIVER-4134 mongo-go-driver - PR #2586: GODRIVER-3787 Inherit timeoutMS at the session level
-
- Closed
-
- is related to
-
GODRIVER-4140 Apply the WithTransaction context deadline to nested AbortTransaction calls
-
- In Progress
-
- related to
-
GODRIVER-2467 Return a Context error if WithTransaction exited due to Context expiration
-
- Backlog
-
1.
|
Cherry-pick 2ddcc43 to release/2.9 | GODRIVER-4142 |
|
In Code Review | Preston Vasquez |