Spanner emulator - hanging transaction

1.1k Views Asked by At

We are using spanner emulator in our sandbox environment. From time to time it happens that some transaction hangs out what is causing following error:

Caused by: com.google.api.gax.rpc.AbortedException: io.grpc.StatusRuntimeException: ABORTED: Transaction 37431 aborted due to active transaction 27078. The emulator only supports one transaction at a time.

The only way we found to make the spanner emulator working again after such an issue is to recreate a database (delete and create) what is quite annoying.

I've tried to kill all sessions listed by gcloud spanner databases sessions list --database=db --instance=sand but it is not helping.

Is there any way to abort/rollback a hanging transaction in spanner emulator?

2

There are 2 best solutions below

2
On

Executing a Rollback RPC for transaction 27078 should do that. That being said, that is not necessarily straightforward:

  1. Which client library / driver are you using? From the error message you posted, it seems to be Java. In that case you could try to construct a RollbackRequest and call the Rollback method in the generated client manually.
  2. How/when does this happen? Normally, the Java client should automatically rollback any failed transaction. Or are you using some other driver than the regular Java client?
0
On

I encountered this issue using Python Client as well. After digging into the code, I found if an exception is raised in a transaction, the transaction will not be closed by the client. From my observation, the cloud Spanner works well on properly closing these hanging transactions on their own, but Spanner Emulator simply doesn't do that.