diff --git a/spanner/client_test.go b/spanner/client_test.go index 83459cafffbb..2dd66094c5e4 100644 --- a/spanner/client_test.go +++ b/spanner/client_test.go @@ -3474,6 +3474,21 @@ func TestReadWriteTransaction_WrapSessionNotFoundError(t *testing.T) { } } +func TestStmtBasedReadWriteTransaction_SessionNotFoundError_shouldNotPanic(t *testing.T) { + t.Parallel() + server, client, teardown := setupMockedTestServer(t) + defer teardown() + server.TestSpanner.PutExecutionTime(MethodBeginTransaction, + SimulatedExecutionTime{ + Errors: []error{newSessionNotFoundError("projects/p/instances/i/databases/d/sessions/s")}, + }) + ctx := context.Background() + tx, _ := NewReadWriteStmtBasedTransaction(ctx, client) + _ = tx.BufferWrite([]*Mutation{Update("my_table", []string{"key", "value"}, []interface{}{int64(1), "my-value"})}) + // This would panic, as it could not refresh the session. + _, _ = tx.Commit(ctx) +} + func TestClient_WriteStructWithPointers(t *testing.T) { t.Parallel() server, client, teardown := setupMockedTestServer(t) diff --git a/spanner/transaction.go b/spanner/transaction.go index 9d52b12f2f3b..5fba4e856966 100644 --- a/spanner/transaction.go +++ b/spanner/transaction.go @@ -1756,6 +1756,7 @@ func NewReadWriteStmtBasedTransactionWithOptions(ctx context.Context, c *Client, txReadyOrClosed: make(chan struct{}), }, } + t.txReadOnly.sp = c.idleSessions t.txReadOnly.sh = sh t.txReadOnly.txReadEnv = t t.txReadOnly.qo = c.qo