Skip to content

Bug: MaxListenersExceededWarning #907

@bonesinc

Description

@bonesinc

Bug description

I'm using Portainer and it tells me after deploying Zipline 4.3.2 that the container is Unhealthy.
I checked the log and found out that after each page access in the web interface it produces a warning:

(node:1) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [ServerResponse]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit.

Output of "--trace-warnings" below.

To (temporary) fix it I had to use Gemini (sorry, not a coder myself) and ended up adding the following to my Portainer Stack config:

services:
  zipline:
    # ... other config
    
    environment:
      # Inject the listener-setting script via NODE_OPTIONS
      # The '-r' flag loads the module before any other application code
      NODE_OPTIONS: "-r /zipline/set-listeners.js"
      # ... other environment variables
    
    # Keep the volume to ensure set-listeners.js exists inside the container
    volumes:
      - PUT_YOUR_PATH_HERE/set-listeners.js:/zipline/set-listeners.js:ro

set-listeners.js

const EventEmitter = require('events');
EventEmitter.defaultMaxListeners = 100; // or a higher number
console.log(`[Startup Fix] EventEmitter.defaultMaxListeners set to ${EventEmitter.defaultMaxListeners}`);

How is Zipline being run?

On docker (docker, docker compose, etc.)

Zipline Version

4.3.2

If applicable, what browsers are you seeing this issue on?

Chromium based (Chrome, Brave, Edge, Opera, etc.)

Relevant Logs

I added 'NODE_OPTIONS: "--trace-warnings"' to the config file, which gives me the following in the log:

(node:1) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [ServerResponse]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit

at genericNodeError (node:internal/errors:983:15)

at wrappedFn (node:internal/errors:537:14)

at _addListener (node:events:593:17)

at ServerResponse.addListener (node:events:611:10)

at eos (node:internal/streams/end-of-stream:209:10)

at Reply.then (/zipline/node_modules/.pnpm/[email protected]/node_modules/fastify/lib/reply.js:459:3)

Steps to Reproduce

Access a page in the web interface and a warning will appear in the log.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions