-
Notifications
You must be signed in to change notification settings - Fork 111
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: session retry could cause infinite wait #616
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,9 @@ class SessionPoolAsyncTransactionManager | |
@GuardedBy("lock") | ||
private TransactionState txnState; | ||
|
||
@GuardedBy("lock") | ||
private AbortedException abortedException; | ||
|
||
private final SessionPool pool; | ||
private volatile PooledSessionFuture session; | ||
private volatile SettableApiFuture<AsyncTransactionManagerImpl> delegate; | ||
|
@@ -159,6 +162,7 @@ public void onError(Throwable t) { | |
if (t instanceof AbortedException) { | ||
synchronized (lock) { | ||
txnState = TransactionState.ABORTED; | ||
abortedException = (AbortedException) t; | ||
} | ||
} | ||
} | ||
|
@@ -167,9 +171,12 @@ public void onError(Throwable t) { | |
public ApiFuture<Timestamp> commitAsync() { | ||
synchronized (lock) { | ||
Preconditions.checkState( | ||
txnState == TransactionState.STARTED, | ||
txnState == TransactionState.STARTED || txnState == TransactionState.ABORTED, | ||
"commit can only be invoked if the transaction is in progress. Current state: " | ||
+ txnState); | ||
if (txnState == TransactionState.ABORTED) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sure that the txn.updateAsync(...); // This aborts the transaction, but the status of the returned ApiFuture is not checked by the application.
...
txn.commitAsync(); |
||
return ApiFutures.immediateFailedFuture(abortedException); | ||
} | ||
txnState = TransactionState.COMMITTED; | ||
} | ||
return ApiFutures.transformAsync( | ||
|
@@ -186,6 +193,7 @@ public void onFailure(Throwable t) { | |
synchronized (lock) { | ||
if (t instanceof AbortedException) { | ||
txnState = TransactionState.ABORTED; | ||
abortedException = (AbortedException) t; | ||
} else { | ||
txnState = TransactionState.COMMIT_FAILED; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,7 @@ class AsyncTransactionStatementImpl<I, O> extends ForwardingApiFuture<O> | |
@Override | ||
public void onFailure(Throwable t) { | ||
mgr.onError(t); | ||
statementResult.setException(t); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This missing statement was what could cause the infinite wait. The result of this specific statement would never be done if the previous statement ( |
||
txnResult.setException(t); | ||
} | ||
|
||
|
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.
This check is no longer needed here as it is checked in the
SessionPoolAsyncTransactionManager
.