Skip to content

Commit

Permalink
fix(spanner): destroy session when client is closing (#6700)
Browse files Browse the repository at this point in the history
* fix(spanner): destroy session when client is closing.

* fix test
  • Loading branch information
rahul2393 committed Sep 21, 2022
1 parent 37d209c commit a1ce541
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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

0 comments on commit a1ce541

Please sign in to comment.