ipx icon indicating copy to clipboard operation
ipx copied to clipboard

MaxListenersExceededWarning: Possible EventEmitter memory leak detected

Open jeanmatthieud opened this issue 3 years ago • 4 comments

I running IPX with npx ipx and some env vars.

I'm getting a lot of warnings in production: MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit

jeanmatthieud avatar Jun 10 '22 10:06 jeanmatthieud

I created a custom node script to start IPX, and increased the limit to "50". I'm still having the issue, with "51" close listeners.

jeanmatthieud avatar Jun 14 '22 09:06 jeanmatthieud

Hi. Do you mind providing a reproduction? 🙏🏼

pi0 avatar Jun 20 '22 16:06 pi0

At first, I was using npx ipx and saw the issue as reported in the issue.

Then, I created a little script, based on cli.ts:

import consola from 'consola'
import { listen } from 'listhen'
import { createIPX, createIPXMiddleware } from 'ipx'
import { EventEmitter } from 'events';

// Added line
EventEmitter.defaultMaxListeners = 50;

async function main() {
  const ipx = createIPX({})
  const middleware = createIPXMiddleware(ipx)
  await listen(middleware, {
    clipboard: false
  })
}

main().catch((err) => {
  consola.error(err)
  process.exit(1)
})

But I'm still getting the issue, with between 20 and 200 requests per minute. All images are stored online, and requested through HTTPS. They are already compressed (JPG 80%) and limited to 1920px per side (so they are not heavy images).

I'm using node 16 and npm 8.5.0.

jeanmatthieud avatar Jun 21 '22 15:06 jeanmatthieud

Me too. And I set the evetemitter's maxListeners to zero. here the code: require('events').EventEmitter.defaultMaxListeners = 0

kyr1eee avatar Jul 26 '22 17:07 kyr1eee