Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeJS generator seems to generate clients with memory leak #1350

Closed
surbhigarg92 opened this issue Mar 7, 2023 · 2 comments
Closed

NodeJS generator seems to generate clients with memory leak #1350

surbhigarg92 opened this issue Mar 7, 2023 · 2 comments
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@surbhigarg92
Copy link

The NodeJS gapic clients seem to have a memory leak that can be triggered using the following steps:

Open a gapic client.
Execute one simple request.
Close the gapic client.
Repeat.

This issue was reported for NodeJS Spanner client library. Internal customer was trying to investigate memory leak issue in Spanner Autoscaler which led them to discover memory leaks in NodeJS Spanner client. Please refer issue . When investigated this further it seems to be more of a generic problem with the generated gapic clients.

Running a simple script that opens a simple generated client, executes one request with it and then closes the client will now leak approx 3MB after 100 iterations.

Test Script

const {Spanner, v1} = require('@google-cloud/spanner');
const REPETITIONS = 100;
console.log(`Running ${REPETITIONS} times`);

function main() {
    async function test() {
        for (let i = 0; i < REPETITIONS; i++) {
            await useGapic();
            global.gc();
            const used = process.memoryUsage().heapUsed / 1024 / 1024;
            console.log(`${i}: Current mem usage ${Math.round(used * 100) / 100} MB`);
        }
    }

    async function useGapic() {
        const client = new v1.InstanceAdminClient({
            projectId: 'my-project',
            keyFile: '/path/to/my-key.json',
        });
        await client.listInstanceConfigs({
            parent: 'projects/my-project',
        });
        await client.close();
    }
    test();
}

process.on('unhandledRejection', err => {
    console.error(err.message);
    process.exitCode = 1;
});
main();

This is continuation to what was also reported in bug

Thanks

@surbhigarg92 surbhigarg92 added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Mar 7, 2023
@alexander-fenster alexander-fenster self-assigned this Mar 7, 2023
@alexander-fenster
Copy link
Contributor

I can repro the leak, looking.

$ node --expose-gc index.js 
Running 100 times
0: Current mem usage 23.25 MB
1: Current mem usage 23.4 MB
2: Current mem usage 23.66 MB
3: Current mem usage 23.77 MB
4: Current mem usage 23.95 MB
5: Current mem usage 24.08 MB
6: Current mem usage 24.17 MB
7: Current mem usage 24.24 MB
8: Current mem usage 24.44 MB
9: Current mem usage 24.57 MB
10: Current mem usage 24.66 MB
11: Current mem usage 24.75 MB
12: Current mem usage 24.82 MB

@alexander-fenster
Copy link
Contributor

Reported to gRPC ↑↑↑

@alexander-fenster alexander-fenster removed their assignment May 24, 2024
@sofisl sofisl closed this as completed May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants