Skip to content

Commit 4e180f4

Browse files
authored
fix(spanner): fix negative values for max_in_use_sessions metrics #10449 (#10508)
* fix(spanner): add debug log to print full stack trace when negative value happens * skip decrementing num_in_use metric count when session is destroyed from healthchecks.
1 parent 25c5cbe commit 4e180f4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

spanner/session.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,11 @@ func (p *sessionPool) incNumInUseLocked(ctx context.Context) {
11911191

11921192
func (p *sessionPool) decNumInUseLocked(ctx context.Context) {
11931193
p.numInUse--
1194+
if int64(p.numInUse) < 0 {
1195+
// print whole call stack trace
1196+
logf(p.sc.logger, "Number of sessions in use is negative, resetting it to currSessionsCheckedOutLocked. Stack trace: %s", string(debug.Stack()))
1197+
p.numInUse = p.currSessionsCheckedOutLocked()
1198+
}
11941199
p.recordStat(ctx, SessionsCount, int64(p.numInUse), tagNumInUseSessions)
11951200
p.recordStat(ctx, ReleasedSessionsCount, 1)
11961201
if p.otConfig != nil {
@@ -1459,12 +1464,12 @@ func (hc *healthChecker) healthCheck(s *session) {
14591464
defer hc.markDone(s)
14601465
if !s.pool.isValid() {
14611466
// Session pool is closed, perform a garbage collection.
1462-
s.destroy(false, true)
1467+
s.destroy(false, false)
14631468
return
14641469
}
14651470
if err := s.ping(); isSessionNotFoundError(err) {
14661471
// Ping failed, destroy the session.
1467-
s.destroy(false, true)
1472+
s.destroy(false, false)
14681473
}
14691474
}
14701475

0 commit comments

Comments
 (0)