This repository was archived by the owner on Mar 4, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 112
This repository was archived by the owner on Mar 4, 2026. It is now read-only.
Client leaks memory - repro provided with single getInstances call. #1306
Copy link
Copy link
Closed
Labels
🚨This issue needs some love.This issue needs some love.api: spannerIssues related to the googleapis/nodejs-spanner API.Issues related to the googleapis/nodejs-spanner API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
I have a specific use case where I need to be able to create multiple Spanner clients with different credentials inside a single long running process. This process is currently leaking memory and crashing.
Environment details
- OS: Ubuntu 20.04
- Node.js version: v14.15.1
- npm version: 6.14.8
@google-cloud/spannerversion: v5.4.0
Steps to reproduce
Run this sample code (after filling in some credentials)
index.js
import { Spanner } from "@google-cloud/spanner";
import { HeapDiff } from "@airbnb/node-memwatch";
// Call the spanner fetch 10 times, outputting memeory after each one
const projectId = "FILL_IN";
const credentials = { client_email: `FILL_IN`, private_key: `FILL IN`};
const REPETITIONS = 10;
console.log(`Running ${REPETITIONS} times`);
for (var i = 0; i < REPETITIONS; i++) {
await getSpannerInstances();
}
async function getSpannerInstances() {
var hd = new HeapDiff();
const spanner = new Spanner({
projectId,
credentials,
});
await spanner.getInstances();
var diff = hd.end();
console.dir(diff.change.size_bytes);
}
package.json
{
"type": "module",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"@airbnb/node-memwatch": "^2.0.0",
"@google-cloud/spanner": "^5.4.0"
}
}
The output indicates that it's leaking around 700-800KB of RAM on each loop through. There's no global state in this simple repro which is indicating that there's something wrong in @google-cloud/spanner
Running 10 times
2601376
914860
899300
729308
779676
797884
764027
790885
729727
759473
Thanks for creating this library and let me know if there are any more diagnostics that I can provide.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
🚨This issue needs some love.This issue needs some love.api: spannerIssues related to the googleapis/nodejs-spanner API.Issues related to the googleapis/nodejs-spanner API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.