node-twitter-api-v2 icon indicating copy to clipboard operation
node-twitter-api-v2 copied to clipboard

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

Open demipixel opened this issue 2 years ago • 4 comments

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

  • Node version: 19
  • Lib version: 1.14.2
  • MacOS Ventural 13.2

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,
      }),
    },
  );

demipixel avatar Mar 01 '23 03:03 demipixel

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

gbourne1 avatar Aug 08 '23 15:08 gbourne1

Is there a resolution for this?

ymittal avatar Oct 09 '23 04:10 ymittal

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).

PLhery avatar Oct 09 '23 14:10 PLhery

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.

alkihis avatar Oct 11 '23 15:10 alkihis