From 84943dab9c95d0d9351450394493bae28161d75c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Wed, 2 Oct 2024 18:04:05 +0200 Subject: [PATCH] chore: check that the session has a lastUseTime (#3363) --- .../src/main/java/com/google/cloud/spanner/SessionPool.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java index 0a7c42477e2..cf50fa44c77 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java @@ -2083,7 +2083,8 @@ private void removeIdleSessions(Instant currTime) { Iterator iterator = sessions.descendingIterator(); while (iterator.hasNext()) { PooledSession session = iterator.next(); - if (session.delegate.getLastUseTime().isBefore(minLastUseTime)) { + if (session.delegate.getLastUseTime() != null + && session.delegate.getLastUseTime().isBefore(minLastUseTime)) { if (session.state != SessionState.CLOSING) { boolean isRemoved = removeFromPool(session); if (isRemoved) { @@ -2676,7 +2677,8 @@ private Tuple findSessionToKeepAlive( && (numChecked + numAlreadyChecked) < (options.getMinSessions() + options.getMaxIdleSessions() - numSessionsInUse)) { PooledSession session = iterator.next(); - if (session.delegate.getLastUseTime().isBefore(keepAliveThreshold)) { + if (session.delegate.getLastUseTime() != null + && session.delegate.getLastUseTime().isBefore(keepAliveThreshold)) { iterator.remove(); return Tuple.of(session, numChecked); }