unleash-client-node icon indicating copy to clipboard operation
unleash-client-node copied to clipboard

Memory leak in deno

Open sveisvei opened this issue 9 months ago • 3 comments

Describe the bug

Hello, We have been running unleash-client-node in Deno for quite a while, and are seeing a steady memory leak for each fetch/poll request. If I increase the polling to each second, it grows and is reproducible in a short time.

Steps to reproduce the bug

1.set up a long running process 2. initiate unleash 3. wait, and see memory increase

Expected behavior

Looks for me to be some retention of objects via make-fetch-happen, its not freed.

Logs, error output, etc.


Screenshots

Image Image

Additional context

I can work on a fix, but would like to discuss a bit first. Should this project even target deno?

Unleash version

No response

Subscription type

Open source

Hosting type

Self-hosted

SDK information (language and version)

No response

sveisvei avatar Apr 02 '25 12:04 sveisvei

I have confirmed the culprit is the use of make-fetch-happen. Using fetch instead, has no memory leak in deno.

I tried updating the version to latest, but problem persists.

Reproduction in this repo:

  1. Change package.json type: commonjs (really optional)
  2. create deno.cjs
const unleash = require('./lib/index.js');

const client = unleash.initialize({
  url: 'https://eu.app.unleash-hosted.com/demo/api/',
  appName: 'my-app',
  instanceId: 'my-instance',
  refreshInterval: 1 * 1000,
  customHeaders: {
    Authorization: 'altsaad:development.397feb4b819e14c623536493b1cf1e0f38faee9e2a9ea16659070ff7',
  },
});

client.on('synchronized', () => {
  console.log('Unleash client synchronized');
});

client.on('error', (error) => {
  console.error('Unleash client error:', error);
});

client.on('ready', () => {
  console.log('Unleash client ready');
});
client.on('update', (data) => {
  console.log('Unleash client update:', data);
});
client.on('registered', (data) => {
  console.log('Unleash client registered:', data);
});
client.on('clientReady', () => {
  console.log('Unleash client ready');
});

console.log('Unleash client initialized:', client.isSynchronized());

setInterval(() => {
  console.log('Unleash client status:', client.isSynchronized(), client.isEnabled('my-feature'));
}, 10_000);

  1. run with npm run build && deno run -A --inspect ./deno.cjs

sveisvei avatar Apr 03 '25 14:04 sveisvei

We're also seeing a memory leak when using Unleash server-side in a Svelte application.

LeonBroeckersAA avatar Apr 15 '25 08:04 LeonBroeckersAA

Is this Deno specific? We are not running Deno but are Node v22 and experiencing the same issue.

coler-j avatar Jul 17 '25 20:07 coler-j