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(spanner): prevent possible panic for Session not found errors #10386

Merged
merged 2 commits into from
Jun 18, 2024
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
15 changes: 15 additions & 0 deletions spanner/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions spanner/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading