Skip to content

Commit

Permalink
fix(spanner): spanner sessions will be cleaned up from the backend (#…
Browse files Browse the repository at this point in the history
…6679)

* fix(spanner): spanner sessions will be cleaned up from the backend

* fix test
  • Loading branch information
rahul2393 committed Sep 19, 2022
1 parent cc4620a commit c27097e
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 17 deletions.
5 changes: 0 additions & 5 deletions spanner/client.go
Expand Up @@ -359,11 +359,6 @@ func (c *Client) BatchReadOnlyTransaction(ctx context.Context, tb TimestampBound
sh *sessionHandle
err error
)
defer func() {
if err != nil && sh != nil {
s.delete(ctx)
}
}()

// Create session.
s, err = c.sc.createSession(ctx)
Expand Down
5 changes: 3 additions & 2 deletions spanner/client_test.go
Expand Up @@ -3250,7 +3250,8 @@ func TestClient_CloseWithUnresponsiveBackend(t *testing.T) {
defer cancel()
sp.close(ctx)

if w, g := context.DeadlineExceeded, ctx.Err(); w != g {
t.Fatalf("context error mismatch\nWant: %v\nGot: %v", w, g)
// session pool close does not trigger any request to backend
if ctx.Err() != nil {
t.Fatalf("context error mismatch\nWant: nil\nGot: %v", ctx.Err())
}
}
2 changes: 0 additions & 2 deletions spanner/session.go
Expand Up @@ -343,8 +343,6 @@ func (s *session) destroyWithContext(ctx context.Context, isExpire bool) bool {
}
// Unregister s from healthcheck queue.
s.pool.hc.unregister(s)
// Remove s from Cloud Spanner service.
s.delete(ctx)
return true
}

Expand Down
8 changes: 0 additions & 8 deletions spanner/session_test.go
Expand Up @@ -417,10 +417,6 @@ func TestTakeFromIdleListChecked(t *testing.T) {
if err != nil {
t.Fatalf("failed to get session: %v", err)
}
ds := server.TestSpanner.DumpSessions()
if g, w := uint64(len(ds)), sp.incStep-1; g != w {
t.Fatalf("number of sessions from mock server mismatch\nGot: %v\nWant: %v\n", g, w)
}
if sh.getID() == wantSid {
t.Fatalf("sessionPool.Take still returns the same session %v, want it to create a new one", wantSid)
}
Expand Down Expand Up @@ -494,10 +490,6 @@ func TestTakeFromIdleWriteListChecked(t *testing.T) {
if err != nil {
t.Fatalf("failed to get session: %v", err)
}
ds := server.TestSpanner.DumpSessions()
if g, w := uint64(len(ds)), sp.incStep-1; g != w {
t.Fatalf("number of sessions from mock server mismatch\nGot: %v\nWant: %v\n", g, w)
}
if sh.getID() == wantSid {
t.Fatalf("sessionPool.Take still returns the same session %v, want it to create a new one", wantSid)
}
Expand Down

0 comments on commit c27097e

Please sign in to comment.