Skip to content
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: AsyncTransactionManager did not always close the session #3580

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public void onSuccess(AsyncTransactionManagerImpl result) {
new ApiFutureCallback<Void>() {
@Override
public void onFailure(Throwable t) {
session.close();
res.setException(t);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutureCallback;
Expand Down Expand Up @@ -1084,6 +1085,37 @@ public void onSuccess(Long aLong) {
}
}

@Test
public void testAbandonedAsyncTransactionManager_rollbackFails() throws Exception {
mockSpanner.setRollbackExecutionTime(
SimulatedExecutionTime.ofException(Status.PERMISSION_DENIED.asRuntimeException()));

boolean gotException = false;
try (AsyncTransactionManager manager = client().transactionManagerAsync()) {
TransactionContextFuture transactionContextFuture = manager.beginAsync();
while (true) {
try {
AsyncTransactionStep<Void, Long> updateCount =
transactionContextFuture.then(
(transactionContext, ignored) ->
transactionContext.executeUpdateAsync(UPDATE_STATEMENT),
executor);
assertEquals(1L, updateCount.get().longValue());
// Break without committing or rolling back the transaction.
break;
} catch (AbortedException e) {
transactionContextFuture = manager.resetForRetryAsync();
}
}
} catch (SpannerException spannerException) {
// The error from the automatically executed Rollback is surfaced when the
// AsyncTransactionManager is closed.
assertEquals(ErrorCode.PERMISSION_DENIED, spannerException.getErrorCode());
gotException = true;
}
assertTrue(gotException);
}

private boolean isMultiplexedSessionsEnabled() {
if (spanner.getOptions() == null || spanner.getOptions().getSessionPoolOptions() == null) {
return false;
Expand Down
Loading