Skip to content

Commit b4595a6

Browse files
authored
fix: do not keep references to invalidated clients (#1093)
SpannerImpl would keep a reference to all database clients that had been created and then invalidated because the database was deleted or did not exists in the first place. If the getDatabaseClient(String) method would be called multiple times for the same invalid database, the memory usage of the application would continue to increase. Fixes #1089
1 parent 7792c90 commit b4595a6

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerImpl.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ private static String nextDatabaseClientId(DatabaseId databaseId) {
9292

9393
private final CloseableExecutorProvider asyncExecutorProvider;
9494

95-
@GuardedBy("this")
96-
private final List<DatabaseClientImpl> invalidatedDbClients = new ArrayList<>();
97-
9895
@GuardedBy("this")
9996
private final Map<DatabaseId, SessionClient> sessionClients = new HashMap<>();
10097

@@ -204,9 +201,8 @@ public DatabaseClient getDatabaseClient(DatabaseId db) {
204201
checkClosed();
205202
String clientId = null;
206203
if (dbClients.containsKey(db) && !dbClients.get(db).pool.isValid()) {
207-
// Move the invalidated client to a separate list, so we can close it together with the
208-
// other database clients when the Spanner instance is closed.
209-
invalidatedDbClients.add(dbClients.get(db));
204+
// Close the invalidated client and remove it.
205+
dbClients.get(db).closeAsync(new ClosedException());
210206
clientId = dbClients.get(db).clientId;
211207
dbClients.remove(db);
212208
}
@@ -253,8 +249,7 @@ void close(long timeout, TimeUnit unit) {
253249
checkClosed();
254250
closedException = new ClosedException();
255251
closureFutures = new ArrayList<>();
256-
invalidatedDbClients.addAll(dbClients.values());
257-
for (DatabaseClientImpl dbClient : invalidatedDbClients) {
252+
for (DatabaseClientImpl dbClient : dbClients.values()) {
258253
closureFutures.add(dbClient.closeAsync(closedException));
259254
}
260255
dbClients.clear();

0 commit comments

Comments
 (0)