-
Notifications
You must be signed in to change notification settings - Fork 131
fix: retry cancelled error on first statement in transaction #999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: retry cancelled error on first statement in transaction #999
Conversation
If the first statement of a read/write transaction fails with a CANCELLED error and the error message is `Read/query was cancelled due to the enclosing transaction being invalidated by a later transaction in the same session.`, then the transaction should be retried, as the error could be caused by a previous statement that was abandoned by the client but still executed by the backend. This could be the case if the statement timed out (on the client) or was cancelled. Fixes #938
Codecov Report
@@ Coverage Diff @@
## master #999 +/- ##
============================================
+ Coverage 85.07% 85.13% +0.06%
- Complexity 2617 2621 +4
============================================
Files 154 154
Lines 14319 14324 +5
Branches 1331 1334 +3
============================================
+ Hits 12182 12195 +13
+ Misses 1569 1566 -3
+ Partials 568 563 -5
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@olavloite without this fix, the user would just see a cancelled
error and no retry would be made automatically, right?
SpannerException exceptionToThrow; | ||
if (withBeginTransaction | ||
&& e.getErrorCode() == ErrorCode.CANCELLED | ||
&& e.getMessage().contains("invalidated by a later transaction")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could we extract a constant for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Correct. That is also exactly what happened in #938. |
If the first statement of a read/write transaction fails with a
CANCELLED
error and the error message isRead/query was cancelled due to the enclosing transaction being invalidated by a later transaction in the same session.
, then the transaction should be retried, as the error could be caused by a previous statement that was abandoned by the client but still executed by the backend. This could be the case if the statement timed out (on the client) or was cancelled.Fixes #938