Skip to content

Memory leak from gc metrics #500

Description

@marwankhalili

I work on a private monolith repository that is having issues with integration tests crashing due to memory leaks.

Managed to narrow down the memory leak to collectDefaultMetrics() in prom-client. Upon investigating the default metrics, I identified that gc was leaking memory. Example using jest --detectLeaks:

'use strict';

it('test gc metrics memory leak', () => {
    const gc = require('../../lib/metrics/gc');
    gc();
});

// > jest --detectLeaks
// FAIL

Looking at the gc metrics source code I noticed that a PerformanceObserver is created but disconnect() is never called (link to documentation).

I confirmed that calling disconnect() fixes the memory leak for our integration tests, as well as the example above.

Assuming we can't disconnect the observer, perhaps we could expose a stop() function that calls disconnect()? As proposed in PR #495 for eventLoopLag.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions