zipline icon indicating copy to clipboard operation
zipline copied to clipboard

Bug: MaxListenersExceededWarning

Open bonesinc opened this issue 2 months ago • 7 comments

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.

bonesinc avatar Oct 17 '25 21:10 bonesinc

this shouldn't be crashing zipline and for the most part should be fine, but I will take a look at it. could you please upload your config as well so I can replicate your environment?

diced avatar Oct 17 '25 21:10 diced

It's not crashing, it just bothered me. Here's my config:

services:
  db:
    image: postgres:17
    container_name: Zipline-DB
    hostname: zipline-db
    security_opt:
      - no-new-privileges:true
    environment:
      POSTGRES_DB: zipline
      POSTGRES_USER: $DB_USER # Hardcoded everywhere in my script
      POSTGRES_PASSWORD: $DB_PASS # Hardcoded everywhere in my script
    volumes:
      - /docker/zipline/db:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD", "pg_isready", "-q", "-d", "zipline", "-U", "$DB_USER"]
      timeout: 45s
      interval: 10s
      retries: 10
    restart: on-failure:5

  zipline:
    image: ghcr.io/diced/zipline
    container_name: Zipline
    ports:
      - '3797:3000'
    environment:
      DATABASE_URL: postgres://$DB_USER:$DB_PASS@zipline-db:5432/zipline
      POSTGRESQL_PASSWORD: $DB_PASS
      CORE_SECRET: $SECRET # Hardcoded in my script
      CORE_PORT: 3000
      CORE_HOSTNAME: 0.0.0.0
      DATASOURCE_TYPE: local
      DATASOURCE_LOCAL_DIRECTORY: /zipline/uploads
      NODE_OPTIONS: "-r /zipline/set-listeners.js --max-http-header-size=32768 --max-old-space-size=4096"
    depends_on:
      db:
        condition: service_healthy
    volumes:
      - /docker/zipline/uploads:/zipline/uploads
      - /docker/zipline/public:/zipline/public
      - /docker/zipline/themes:/zipline/themes
      - /docker/zipline/maxlisteners-fix/set-listeners.js:/zipline/set-listeners.js:ro
    healthcheck:
      test: ['CMD', 'wget', '-q', '--spider', 'http://127.0.0.1:3000/api/healthcheck']
      interval: 15s
      timeout: 2s
      retries: 2
    restart: on-failure:5

bonesinc avatar Oct 18 '25 09:10 bonesinc

I'm facing the same issue on a brand new install. Using default docker compose. s3 storage, and reverse proxy via Caddy.

yashendra2797 avatar Oct 22 '25 16:10 yashendra2797

(@yashendra2797 @bonesinc) could either one of you send the output of docker compose exec zipline pnpm ctl read-config? please make sure to redact sensitive information like keys or oauth secrets.

diced avatar Oct 22 '25 23:10 diced

Here's the output while running zipline 'unfixed'.

zipline_config_output.txt

bonesinc avatar Oct 25 '25 08:10 bonesinc

I'm having the same issue on a fresh installation. It keeps happening when I turn on "Enable View Routes" and "Enable Embed".

TuxEnthusiast avatar Nov 13 '25 16:11 TuxEnthusiast

I'm also experiencing the exact same issue.. it's been happening to me for months, but I never really bothered to report it until now. I also have View Routes and Embeds enabled.

root@4c4f56loss:/opt/zipline # docker compose exec zipline pnpm ctl read-config

> [email protected] ctl /zipline
> NODE_ENV=production node --require dotenv/config --enable-source-maps ./build/ctl read-config

[2025-11-20T20:42:47 INFO   db] connecting to database url="postgres://zipline:REDACTED@postgresql:5432/zipline"
[2025-11-20T20:42:48 INFO   config::read] overriding database value from env col="coreDefaultDomain" value="zip.lovinoes.de"
[2025-11-20T20:42:48 INFO   config::read] overriding database value from env col="featuresUserRegistration" value=false
[2025-11-20T20:42:48 INFO   config::read] overriding database value from env col="websiteTitle" value="lovinoes.de"
[2025-11-20T20:42:48 INFO   config::read] overriding database value from env col="websiteTitleLogo" value="https://cdn.lovinoes.de/files/lovinoes/lovinoes3.png"
{"core":{"port":3000,"hostname":"0.0.0.0","secret":"REDACTED","returnHttpsUrls":true,"defaultDomain":"zip.lovinoes.de","tempDirectory":"/tmp/zipline","trustProxy":true,"databaseUrl":"postgres://zipline:REDACTED@postgresql:5432/zipline","database":{"username":null,"password":null,"host":null,"port":null,"name":null}},"chunks":{"max":"95mb","size":"25mb","enabled":true},"tasks":{"deleteInterval":"30m","clearInvitesInterval":"30m","maxViewsInterval":"30m","thumbnailsInterval":"30m","metricsInterval":"30m"},"files":{"route":"/u","length":6,"defaultFormat":"random","disabledExtensions":[],"maxFileSize":"100mb","defaultExpiration":null,"assumeMimetypes":false,"defaultDateFormat":"YYYY-MM-DD_HH:mm:ss","removeGpsMetadata":false,"randomWordsNumAdjectives":2,"randomWordsSeparator":"-","defaultCompressionFormat":"jpg"},"urls":{"route":"/go","length":6},"datasource":{"type":"local","local":{"directory":"./uploads"}},"features":{"imageCompression":true,"robotsTxt":true,"healthcheck":true,"userRegistration":false,"oauthRegistration":false,"deleteOnMaxViews":true,"thumbnails":{"enabled":true,"num_threads":4,"format":"jpg"},"metrics":{"enabled":true,"adminOnly":false,"showUserSpecific":true},"versionChecking":true,"versionAPI":"https://zipline-version.diced.sh"},"domains":[],"invites":{"enabled":true,"length":6},"website":{"title":"lovinoes.de","titleLogo":"https://cdn.lovinoes.de/files/lovinoes/lovinoes3.png","externalLinks":[{"name":"GitHub","url":"https://github.com/diced/zipline"},{"name":"Documentation","url":"https://zipline.diced.sh/"}],"loginBackground":"https://cdn.lovinoes.de/files/wallpaper/unsplash/unsplash-15-dark-1080p.jpg","loginBackgroundBlur":true,"defaultAvatar":null,"theme":{"default":"builtin:dark_blue","dark":"builtin:dark_blue","light":"builtin:dark_blue"},"tos":null},"mfa":{"totp":{"enabled":true,"issuer":"Zipline"},"passkeys":true},"oauth":{"bypassLocalLogin":false,"loginOnly":false,"discord":{"allowedIds":[],"deniedIds":[]},"github":{},"google":{},"oidc":{}},"discord":null,"ratelimit":{"enabled":true,"max":10,"window":null,"adminBypass":true,"allowList":[]},"httpWebhook":{"onUpload":null,"onShorten":null},"ssl":{"key":"REDACTED","cert":"REDACTED"},"pwa":{"enabled":true,"title":"Zipline","shortName":"Zipline","description":"Zipline - zip.lovinoes.de","themeColor":"#000000","backgroundColor":"#000000"}}
root@4c4f56loss:/opt/zipline #

I should also mention this ig.

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

Lovinoes avatar Nov 20 '25 20:11 Lovinoes

I can confirm I am also receiving this issue, unusual memory usage increase from my monitoring (>120~170mb on average)

xFGhoul avatar Dec 13 '25 03:12 xFGhoul