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.
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()inprom-client. Upon investigating the default metrics, I identified thatgcwas leaking memory. Example usingjest --detectLeaks: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 callsdisconnect()? As proposed in PR #495 foreventLoopLag.