Multivit4min / TS3-NodeJS-Library

TeamSpeak 3 Server Query Library supports SSH and RAW Query
https://multivit4min.github.io/TS3-NodeJS-Library/
MIT License
150 stars 19 forks source link

High memory usage over time #40

Closed elipeF closed 5 years ago

elipeF commented 5 years ago

Describe the bug Saturation of the memory by the bot without any errors

To Reproduce

const ts3 = new TeamSpeak3({
  host: 'blabla',
  queryport: 10022,
  protocol: 'ssh',
  serverport: 'blabla',
  username: 'blabla',
  password: 'blabla',
  nickname: 'blabla',
  keepalive: true,
});

ts3.on('error', err => {
  console.log(err);
});

ts3.setMaxListeners(0);

ts3.on('clientconnect', async ev => {
  const { client } = ev;
  // for example simple if to check if client nickname include some char
});

ts3.on('ready', async () => {
  try {
    await ts3.registerEvent('server');
    const users = await ts3.clientList();
    for (const user of users) {
      // same of as higher
    }
  } catch (e) {
    console.log(e);
  }
});

Expected behavior To clear or reduce memory usage somehow.

Versions used

Additional context Nothing special happened here, but this "nothing" takes 4GB of RAM and that's terrifying. The use of memory grows over time and does not diminish. Even if there is zero traffic on the server, the memory usage increases. I think it's the fault of the "clientconnect" event which probably saves information about the user but does not clean them after the user left the server (Correct me if I'm wrong)

Multivit4min commented 5 years ago

How much users do you have average on your TeamSpeak Server? It might be that i do not release the event listeners correctly

Multivit4min commented 5 years ago

I published a newer version to npm -> 1.12.5 would appreciate feedback if it has worked for you :)

elipeF commented 5 years ago

On my own 500. Also tested on server with 200(users spend more time session take more time memory increase slowly than on my first one). If you solved it I can test it out. Also I'm looking for solution but no PR ready for now.

elipeF commented 5 years ago

I published a newer version to npm -> 1.12.5 would appreciate feedback if it has worked for you :)

I deployed it. I will add the answer tomorrow after it has been going through for some time

elipeF commented 5 years ago

@Multivit4min I can confirm that everything works as it should. After 6 hours of work, the memory usage did not increase. Good job!