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): destroy session when client is closing #6700

Merged
merged 4 commits into from Sep 21, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions spanner/session.go
Expand Up @@ -25,6 +25,7 @@ import (
"math"
"math/rand"
"runtime/debug"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -1723,3 +1724,12 @@ func isSessionNotFoundError(err error) bool {
}
return false
}

// isClientClosing returns true if the given error is a
// `Connection is closing` error.
func isClientClosing(err error) bool {
if err == nil {
return false
}
return ErrCode(err) == codes.Canceled && strings.Contains(err.Error(), "the client connection is closing")
}
2 changes: 1 addition & 1 deletion spanner/transaction.go
Expand Up @@ -779,7 +779,7 @@ func (t *ReadOnlyTransaction) release(err error) {
sh := t.sh
t.mu.Unlock()
if sh != nil { // sh could be nil if t.acquire() fails.
if isSessionNotFoundError(err) {
if isSessionNotFoundError(err) || isClientClosing(err) {
sh.destroy()
}
if t.singleUse {
Expand Down