RemoteMetering / geteventstore-promise

An EventStore http+tcp wrapper package
MIT License
31 stars 17 forks source link

Memory leak on reset client #100

Closed matchish closed 3 years ago

matchish commented 3 years ago

If I want to resubscribe to a stream

const client: TCPClient = clientFactory()
    for (;;) {
      const subscription = await client.subscribeToStreamFrom('$ce-Company', 0, () => {});
      (await client.getPool()).clear()
      subscription.stop()
      const memory = process.memoryUsage()
      console.log(`Memory used ${memory.heapUsed}`)
    }

Memory consumption increasing every loop

mmuller99 commented 3 years ago

Hi @matchish, stopping a subscribeToStreamFrom subscription does not dispose of the underlying connection. Please use the newly added close function which will stop the subscription and release and destroy the singular connection pool used for subscriptions.

const client: TCPClient = clientFactory()
    for (;;) {
      const subscription = await client.subscribeToStreamFrom('$ce-Company', 0, () => {});
      subscription.close();
      const memory = process.memoryUsage();
      console.log(`Memory used ${memory.heapUsed}`);
    }