GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Reading from a non-existent database causes memory usage to grow · Issue #1089 · googleapis/java-spanner

This repository was archived by the owner on Aug 30, 2026. It is now read-only.
This repository was archived by the owner on Aug 30, 2026. It is now read-only.

Reading from a non-existent database causes memory usage to grow #1089

Copy link
Copy link
Closed
#1093
Closed
Reading from a non-existent database causes memory usage to grow#1089
#1093
Copy link
Assignees
thiagotnunesolavloite
Labels
api: spannerIssues related to the googleapis/java-spanner API.triage meI really want to be triaged.

Description

@sebright2
sebright2
opened on Apr 23, 2021
Issue body actions

It seems like requests that fail with a NOT_FOUND error can cause the Spanner client to consume memory. I suspect that it is caused by the invalidatedDbClients field in SpannerImpl:

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

Line 96 in 71d7fd1

private final List<DatabaseClientImpl> invalidatedDbClients = new ArrayList<>();

I ran this test program to reproduce the issue with Java 11 and google-cloud-spanner 6.3.2:

import com.google.cloud.spanner.DatabaseId;
import com.google.cloud.spanner.InstanceConfigId;
import com.google.cloud.spanner.InstanceId;
import com.google.cloud.spanner.InstanceInfo;
import com.google.cloud.spanner.Key;
import com.google.cloud.spanner.Spanner;
import com.google.cloud.spanner.SpannerOptions;
import java.util.Arrays;
import org.junit.Test;

public class FailedRequestMemoryUsageTest {

  @Test
  public void testFailedRequestMemoryUsage() throws Exception {
    Spanner spanner = SpannerOptions.getDefaultInstance().getService();
    String projectId = spanner.getOptions().getProjectId();
    InstanceId instanceId = InstanceId.of(projectId, "my-instance");
    InstanceConfigId instanceConfigId = InstanceConfigId.of(projectId, "regional-us-central1");
    spanner
        .getInstanceAdminClient()
        .createInstance(
            InstanceInfo.newBuilder(instanceId)
                .setInstanceConfigId(instanceConfigId)
                .setDisplayName("my-instance")
                .setNodeCount(1)
                .build())
        .get();
    DatabaseId databaseId = DatabaseId.of(instanceId, "my-database");

    for (int i = 0; i <= 10000; i++) {
      if (i % 500 == 0) {
        Runtime.getRuntime().gc();
        System.out.println(
            i + "\t" + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
      }
      try {
        spanner
            .getDatabaseClient(databaseId)
            .singleUse()
            .readRow("MyTable", Key.of(0), Arrays.asList("MyColumn"));
      } catch (Exception e) {
        // Ignore NOT_FOUND error
      }
    }
  }
}
0	19573984
500	31193384
1000	35718312
1500	40337512
2000	44895408
2500	49444864
3000	54109824
3500	58690984
4000	63295664
4500	68078928
5000	72855264
5500	77463136
6000	82355544
6500	86576208
7000	91327472
7500	95821992
8000	100438752
8500	105055256
9000	109650504
9500	114148912
10000	118900040

java-spanner-memory-usage

Activity

  1. blunderbuss-gcf
    assigned
    thiagotnunes
    on Apr 23, 2021
  2. product-auto-label
    added
    api: spannerIssues related to the googleapis/java-spanner API.
    on Apr 23, 2021
  3. olavloite
    self-assigned this
    on Apr 23, 2021
  4. olavloite
    added a commit that references this issue on Apr 23, 2021

    fix: do not keep references to invalidated clients

    This issue will close once commit 031b6d2 is merged into the 'main' branch.
    031b6d2
  5. yoshi-automation
    added
    triage meI really want to be triaged.
    on Apr 25, 2021
  6. thiagotnunes
    closed this as completedin #1093on Apr 25, 2021
  7. thiagotnunes
    added a commit that references this issue on Apr 25, 2021

    fix: do not keep references to invalidated clients (#1093)

    This issue will close once commit b4595a6 is merged into the 'main' branch.
    b4595a6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @olavloite
    olavloite
  • @thiagotnunes
    thiagotnunes

Labels

api: spannerIssues related to the googleapis/java-spanner API.triage meI really want to be triaged.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.