Commit 2875e821 authored by Leonard Hecker's avatar Leonard Hecker Committed by Knut Olav Løite
Browse files

spanner: Fixed session leakage for ApplyAtLeastOnce

Previously session handles where leaked whenever Commit() returned a
non-abort, non-session-not-found error, due to a missing recycle() call.

Fixes #1776.

Change-Id: I45839d3258f96bf6d1dfc15c35e6e146117d70f1
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/51890

Reviewed-by: default avatarkokoro <[email protected]>
Reviewed-by: default avatarShanika Kuruppu <[email protected]>
Reviewed-by: default avatarKnut Olav Løite <[email protected]>
parent 281e3bbe
......@@ -130,6 +130,11 @@ func (sh *sessionHandle) getTransactionID() transactionID {
func (sh *sessionHandle) destroy() {
sh.mu.Lock()
s := sh.session
if s == nil {
// sessionHandle has already been recycled.
sh.mu.Unlock()
return
}
tracked := sh.trackedSessionHandle
sh.session = nil
sh.trackedSessionHandle = nil
......@@ -137,10 +142,6 @@ func (sh *sessionHandle) destroy() {
sh.stack = nil
sh.mu.Unlock()
if s == nil {
// sessionHandle has already been destroyed..
return
}
if tracked != nil {
p := s.pool
p.mu.Lock()
......
......@@ -1018,6 +1018,7 @@ func (t *writeOnlyTransaction) applyAtLeastOnce(ctx context.Context, ms ...*Muta
// creations/retrivals.
return ts, err
}
defer sh.recycle()
}
res, err := sh.getClient().Commit(contextWithOutgoingMetadata(ctx, sh.getMetadata()), &sppb.CommitRequest{
Session: sh.getID(),
......@@ -1043,9 +1044,6 @@ func (t *writeOnlyTransaction) applyAtLeastOnce(ctx context.Context, ms ...*Muta
break
}
}
if sh != nil {
sh.recycle()
}
return ts, toSpannerError(err)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment