-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
api: spannerIssues related to the Spanner API.Issues related to the Spanner API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
If an exception that cannot be retried occurs while executing the BeginTransaction gRPC, the Spanner session pool could leak a session.
Consider the following example:
SpannerOptions.Builder builder =
SpannerOptions.newBuilder()
.setProjectId("[PROJECT]")
builder.setSessionPoolOption(
SessionPoolOptions.newBuilder()
.setMinSessions(0)
.setMaxSessions(2)
.setWriteSessionsFraction(0.0f)
.build());
Spanner spanner = builder.build().getService();
DatabaseClient client =
spanner.getDatabaseClient(DatabaseId.of("[PROJECT]", "[INSTANCE]", "[DATABASE]"));
TransactionRunner runner = client.readWriteTransaction();
long updateCount =
runner.run(
new TransactionCallable<Long>() {
@Override
public Long run(TransactionContext transaction) throws Exception {
return transaction.executeUpdate(UPDATE_STATEMENT);
}
});The above session pool will never contain a prepared transaction, as the writeSessionsFraction is set to 0. Creating a read/write transaction will therefore always require the session pool to prepare a new session. If the BeginTransaction rpc returns a non-retryable error, the error is returned to the client, but the session that is taken to be prepared by the session pool is never returned to the session pool.
Metadata
Metadata
Assignees
Labels
api: spannerIssues related to the Spanner API.Issues related to the Spanner API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.