PLhery / node-twitter-api-v2

Strongly typed, full-featured, light, versatile yet powerful Twitter API v1.1 and v2 client for Node.js.
https://www.npmjs.com/package/twitter-api-v2
Apache License 2.0
1.29k stars 176 forks source link

[bug] Support Node v19's default Keep-Alive #455

Open demipixel opened 1 year ago

demipixel commented 1 year ago

Describe the bug After making enough requests, I get:

(node:31573) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit

To Reproduce

  1. Use Node v19 where Keep Alive is enabled by default
  2. Make 10 requests (say, just fetch a user)

Expected behavior Error should not appear

Version

Additional context

The same socket gets reused in node v19. This means the same "close" handler gets added repeatedly.

My temporary solution is to force node to use a new socket for each request, but of course that's not ideal:

import https from 'https';

client = new TwitterApi(
    configHere,
    {
      httpAgent: new https.Agent({
        keepAlive: false,
      }),
    },
  );
gbourne1 commented 1 year ago

Also an issue with Node 20. Setting the keepAlive to false gives a lot of uncaught exceptions and issues uploading.

ymittal commented 12 months ago

Is there a resolution for this?

PLhery commented 12 months ago

Hello, We are not actively maintaining this library anymore since it became X ; if someone wants to propose a PR, feel free and I'll accept it (as long as it makes sense).

alkihis commented 12 months ago

Hello, I've made a workaround to cleanup socket listeners after a request is completed in 1.15.2 release, the "MaxListenersExceededWarning" message should not appear anymore.

Any other issue happening due to keep-alive (true or false) giving uncaught exceptions must be addressed in another issue if any.