unjs / ipx

🖼️ High performance, secure and easy-to-use image optimizer.
MIT License
1.54k stars 61 forks source link

MaxListenersExceededWarning: Possible EventEmitter memory leak detected #72

Open jeanmatthieud opened 2 years ago

jeanmatthieud commented 2 years ago

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 commented 2 years ago

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.

pi0 commented 2 years ago

Hi. Do you mind providing a reproduction? 🙏🏼

jeanmatthieud commented 2 years ago

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.

kyr1eee commented 2 years ago

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