MaxListenersExceededWarning: how to use "emitter.setMaxListeners" and avoid reaching the time limit?

Hi there,

I’m building jamstack.club with Hugo and Netlify, and I’m facing numerous errors MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGHUP listeners added to [process]. Use emitter.setMaxListeners() to increase limit

The build then fails with the following error: Error running command: Command did not finish within the time limit

Here is the Nelify site name: jamstackclub.netlify.app
And the full build log:

6:58:29 AM: build-image version: 20e1f1f500e4cbad9ea8a99bd40807bef3093551 (focal)
6:58:29 AM: buildbot version: 00a030bf3c001e3c0d5d2d5931d77655af9653ed
6:58:29 AM: Fetching cached dependencies
6:58:29 AM: Failed to fetch cache, continuing with build
6:58:29 AM: Starting to prepare the repo for build
6:58:29 AM: No cached dependencies found. Cloning fresh repo
6:58:29 AM: git clone --filter=blob:none git@gitlab.com:Roneo/jamstack.club
6:58:31 AM: Preparing Git Reference refs/heads/main
6:58:42 AM: Starting to install dependencies
6:58:42 AM: Python version set to 3.8
6:58:42 AM: Attempting Ruby version 2.7.2, read from environment
6:58:43 AM: Using Ruby version 2.7.2
6:58:44 AM: Started restoring cached go cache
6:58:44 AM: Finished restoring cached go cache
6:58:44 AM: Installing Go version 1.16.5 (requested 1.16.5)
6:58:48 AM: go version go1.16.5 linux/amd64
6:58:48 AM: Using PHP version 8.0
6:58:48 AM: Installing Hugo 0.71.1
6:58:49 AM: Hugo Static Site Generator v0.71.1-A301F6B2/extended linux/amd64 BuildDate: 2020-05-25T09:18:12Z
6:58:50 AM: Downloading and installing node v16.20.2...
6:58:50 AM: Downloading https://nodejs.org/dist/v16.20.2/node-v16.20.2-linux-x64.tar.xz...
6:58:50 AM: Computing checksum with sha256sum
6:58:50 AM: Checksums matched!
6:58:52 AM: Now using node v16.20.2 (npm v8.19.4)
6:58:52 AM: Enabling Node.js Corepack
6:58:52 AM: Started restoring cached build plugins
6:58:52 AM: Finished restoring cached build plugins
6:58:52 AM: Started restoring cached corepack dependencies
6:58:52 AM: Finished restoring cached corepack dependencies
6:58:52 AM: No npm workspaces detected
6:58:52 AM: Started restoring cached node modules
6:58:52 AM: Finished restoring cached node modules
6:58:53 AM: Installing npm packages using npm version 8.19.4
6:59:02 AM: npm WARN deprecated puppeteer@5.5.0: < 19.4.0 is no longer supported
6:59:10 AM: added 352 packages, and audited 353 packages in 17s
6:59:10 AM: 94 packages are looking for funding
6:59:10 AM:   run `npm fund` for details
6:59:10 AM: 12 vulnerabilities (4 moderate, 7 high, 1 critical)
6:59:10 AM: To address issues that do not require attention, run:
6:59:10 AM:   npm audit fix
6:59:10 AM: To address all issues (including breaking changes), run:
6:59:10 AM:   npm audit fix --force
6:59:10 AM: Run `npm audit` for details.
6:59:10 AM: npm packages installed
6:59:10 AM: Install dependencies script success
6:59:10 AM: Starting build script
6:59:11 AM: Detected 2 framework(s)
6:59:11 AM: hugo at version unknown
6:59:11 AM: zola at version unknown
6:59:11 AM: Section completed: initializing
6:59:13 AM: ​
6:59:13 AM: Netlify Build                                                 
6:59:13 AM: ────────────────────────────────────────────────────────────────
6:59:13 AM: ​
6:59:13 AM: ❯ Version
6:59:13 AM:   @netlify/build 29.19.0
6:59:13 AM: ​
6:59:13 AM: ❯ Flags
6:59:13 AM:   baseRelDir: true
6:59:13 AM:   buildId: 64d5bff28e0cde28f3aa228f
6:59:13 AM:   deployId: 64d5bff28e0cde28f3aa2291
6:59:13 AM: ​
6:59:13 AM: ❯ Current directory
6:59:13 AM:   /opt/build/repo
6:59:13 AM: ​
6:59:13 AM: ❯ Config file
6:59:13 AM:   /opt/build/repo/netlify.toml
6:59:13 AM: ​
6:59:13 AM: ❯ Context
6:59:13 AM:   production
6:59:13 AM: ​
6:59:13 AM: ❯ Installing plugins
6:59:13 AM:    - @netlify/plugin-lighthouse@4.1.1
6:59:22 AM: ​
6:59:22 AM: ❯ Loading plugins
6:59:22 AM:    - @netlify/plugin-lighthouse@4.1.1 from Netlify app
6:59:22 AM: ​
6:59:22 AM: ❯ Outdated plugins
6:59:22 AM:    - @netlify/plugin-lighthouse@4.1.1: latest version is 5.0.0
6:59:22 AM:      To upgrade this plugin, please uninstall and re-install it from the Netlify plugins directory (https://app.netlify.com/plugins)
6:59:23 AM: ​
6:59:23 AM: build.command from netlify.toml                               
6:59:23 AM: ────────────────────────────────────────────────────────────────
6:59:23 AM: ​
6:59:23 AM: $ npm install && npm run deploy
6:59:24 AM: up to date, audited 353 packages in 623ms
6:59:24 AM: 94 packages are looking for funding
6:59:24 AM:   run `npm fund` for details
6:59:24 AM: 12 vulnerabilities (4 moderate, 7 high, 1 critical)
6:59:24 AM: To address issues that do not require attention, run:
6:59:24 AM:   npm audit fix
6:59:24 AM: To address all issues (including breaking changes), run:
6:59:24 AM:   npm audit fix --force
6:59:24 AM: Run `npm audit` for details.
6:59:25 AM: > deploy
6:59:25 AM: > node ./scripts/build.js --latest && hugo --minify
6:59:25 AM: Processing latest themes
6:59:25 AM: - Fetching Github Data
7:03:15 AM: ✔ Success - Fetching Github Data
7:03:15 AM: Writing /opt/build/repo/data/themes.json...
7:03:15 AM: - Fetching Stackbit Data
7:03:15 AM: ✔ Success - Fetching Stackbit Data
7:03:15 AM: Writing /opt/build/repo/data/stackbit.json...
7:05:39 AM: - Testing Demo URL's
✔ Success - Testing Demo URL's
- Capturing Screenshots
7:14:17 AM: (node:4288) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added to [process]. Use emitter.setMaxListeners() to increase limit
7:14:17 AM: (Use `node --trace-warnings ...` to show where the warning was created)
7:14:17 AM: (node:4288) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added to [process]. Use emitter.setMaxListeners() to increase limit
7:14:17 AM: (node:4288) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGTERM listeners added to [process]. Use emitter.setMaxListeners() to increase limit
7:14:17 AM: (node:4288) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGHUP listeners added to [process]. Use emitter.setMaxListeners() to increase limit
7:30:39 AM: ✔ Success - Capturing Screenshots
7:30:39 AM: - Generating Thumbnails
7:30:40 AM: ✔ Success - Generating Thumbnails
7:30:40 AM: Writing /opt/build/repo/data/errors.json...
7:30:40 AM: Build Successful
7:30:40 AM: Error Log
7:30:46 AM: Building sites …
7:30:46 AM:                    |  EN
7:30:46 AM: -------------------+-------
7:30:46 AM:   Pages            | 2402
7:30:46 AM:   Paginator pages  |   95
7:30:46 AM:   Non-page files   |    2
7:30:46 AM:   Static files     | 3452
7:30:46 AM:   Processed images |    0
7:30:46 AM:   Aliases          |   67
7:30:46 AM:   Sitemaps         |    1
7:30:46 AM:   Cleaned          |    0
7:30:46 AM: Total in 5819 ms
7:30:46 AM: ​
7:30:46 AM: (build.command completed in 31m 22.4s)
7:30:46 AM: ​
7:30:46 AM: Functions bundling                                            
7:30:46 AM: ────────────────────────────────────────────────────────────────
7:30:46 AM: ​
7:30:46 AM: Packaging Functions from netlify/functions directory:
7:30:46 AM:  - submission-created.js
7:30:46 AM: ​
7:30:46 AM: ​
7:30:46 AM: (Functions bundling completed in 111ms)
7:30:46 AM: ​
7:30:46 AM: @netlify/plugin-lighthouse (onPostBuild event)                
7:30:46 AM: ────────────────────────────────────────────────────────────────
7:30:46 AM: ​
7:30:46 AM: Generating Lighthouse report. This may take a minute…
7:30:46 AM: Running Lighthouse on public/
7:30:46 AM: Serving and scanning site from directory public
7:31:07 AM: Lighthouse scores for public/
7:31:07 AM: - Performance: 94
7:31:07 AM: - Accessibility: 98
7:31:07 AM: - Best Practices: 92
7:31:07 AM: - SEO: 100
7:31:07 AM: - PWA: 70
7:31:07 AM: ​
7:31:07 AM: (@netlify/plugin-lighthouse onPostBuild completed in 20.5s)
7:31:07 AM: ​
7:31:07 AM: Deploy site                                                   
7:31:07 AM: ────────────────────────────────────────────────────────────────
7:31:07 AM: ​
7:31:07 AM: Starting to deploy site from 'public'
7:31:07 AM: Calculating files to upload
7:31:14 AM: 752 new files to upload
7:31:14 AM: 1 new functions to upload
7:31:14 AM: Starting to upload
7:31:14 AM: 10% uploaded
7:31:14 AM: 20% uploaded
7:31:14 AM: 30% uploaded
7:31:15 AM: 40% uploaded
7:31:17 AM: Starting post processing
7:31:17 AM: Post processing - HTML
7:31:17 AM: Failed during stage 'building site': Command did not finish within the time limit
7:31:17 AM: ---------------------------------------------------------------------
DEPRECATION NOTICE: Your site has asset optimization enabled. This feature will be at end of service on October 17, 2023.

After that date, your builds will continue to work but we won't minify or bundle the CSS and JS, and we won't optimize images.
To remove this warning, disable asset optimization in your site configuration:
https://app.netlify.com/sites/jamstackclub/configuration/deploys#asset-optimization


For more details, read our forum announcement:
https://answers.netlify.com/t/please-read-deprecation-of-post-processing-asset-optimization/96657
---------------------------------------------------------------------

7:31:15 AM: 50% uploaded
7:31:15 AM: 60% uploaded
7:31:15 AM: 70% uploaded
7:31:16 AM: 80% uploaded
7:31:16 AM: 90% uploaded
7:31:16 AM: 100% uploaded
7:31:16 AM: Section completed: deploying
7:31:16 AM: Site deploy was successfully initiated
7:31:16 AM: ​
7:31:16 AM: (Deploy site completed in 9.5s)
7:31:16 AM: ​
7:31:16 AM: Netlify Build Complete                                        
7:31:16 AM: ────────────────────────────────────────────────────────────────
7:31:16 AM: ​
7:31:16 AM: (Netlify Build completed in 32m 3.7s)
7:31:17 AM: Execution timed out after 32m6.560957766s
7:31:17 AM: Error running command: Command did not finish within the time limit
7:31:17 AM: Failing build: Failed to build site
7:31:17 AM: Finished processing build request in 32m48.78s

The build requires to fetch data from Github and generate a large amount of screenshots, and thus requires a large amount of time.

Should I try to fix the error about MaxListeners or is it a problem related to Netlify time limit?
How to avoid reaching this time limit, or increase the allowed build time?

I’ve increased the build’s time limit to an hour. Let’s see what changes does that make.

A build was successfull since then, thanks!
I’m marking this issue as solved, I’ll let you know if the same problem occurs again

Hi @hrishikesh , the same problem is back again, could you please have a look?

Here is the error message:

12:03:22 AM: (node:4416) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added to [process]. Use emitter.setMaxListeners() to increase limit
12:03:22 AM: (Use `node --trace-warnings ...` to show where the warning was created)
12:03:22 AM: (node:4416) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added to [process]. Use emitter.setMaxListeners() to increase limit

Thank you!

Hi, I can increase your build timeout to 90 minute to see if that helps? Alternatively i’d recommend you look into optimising your build.

Hi im having same issue can help on this pls

May 24, 09:32:51 AM: build-image version: 2be63b793c62ef8e32317f27dbcfe59c48c048e5 (focal)
May 24, 09:32:51 AM: devbot version: 824ae472ac144313f8511179632b58d4df7435cf
May 24, 09:32:51 AM: Building without cache
May 24, 09:32:51 AM: Starting to prepare your repo
May 24, 09:32:52 AM: No cached dependencies found. Cloning fresh repo
May 24, 09:32:52 AM: git clone --filter=blob:none https://github.com/suresh9416/studio
May 24, 09:32:52 AM: Preparing Git Reference preview
May 24, 09:32:54 AM: Starting to install dependencies
May 24, 09:32:55 AM: e[2mmisee[0m e[34mpythone[0m@3.8.20   install
May 24, 09:32:55 AM: e[2mmisee[0m e[34mpythone[0m@3.8.20   download cpython-3.8.20+20241002-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz
May 24, 09:32:55 AM: e[2mmisee[0m e[34mpythone[0m@3.8.20   extract cpython-3.8.20+20241002-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz
May 24, 09:32:55 AM: e[2mmisee[0m e[34mpythone[0m@3.8.20   python --version
May 24, 09:32:55 AM: e[2mmisee[0m e[34mpythone[0m@3.8.20   Python 3.8.20
May 24, 09:32:55 AM: e[2mmisee[0m e[34mpythone[0m@3.8.20 e[38;5;10m✓e[0m installed
May 24, 09:32:55 AM: mise e[36m/opt/build/repo/mise.tomle[0m tools: e[34mpythone[0m@3.8.20
May 24, 09:32:55 AM: Python version set to 3.8
May 24, 09:32:55 AM: mise e[36m/opt/build/repo/mise.tomle[0m tools: e[34mpythone[0m@3.8.20
May 24, 09:32:55 AM: Attempting Ruby version 2.7.2, read from environment
May 24, 09:32:56 AM: Using Ruby version 2.7.2
May 24, 09:32:56 AM: mise e[36m/opt/build/repo/mise.tomle[0m tools: e[34mpythone[0m@3.8.20
May 24, 09:32:57 AM: Started restoring cached go cache
May 24, 09:32:57 AM: Finished restoring cached go cache
May 24, 09:32:57 AM: Installing Go version 1.19.5 (requested 1.19.5)
May 24, 09:33:03 AM: go version go1.19.5 linux/amd64
May 24, 09:33:03 AM: mise e[36m/opt/build/repo/mise.tomle[0m tools: e[34mpythone[0m@3.8.20
May 24, 09:33:03 AM: mise e[36m/opt/build/repo/mise.tomle[0m tools: e[34mpythone[0m@3.8.20
May 24, 09:33:03 AM: mise e[36m/opt/build/repo/mise.tomle[0m tools: e[34mpythone[0m@3.8.20
May 24, 09:33:04 AM: mise e[36m/opt/build/repo/mise.tomle[0m tools: e[34mpythone[0m@3.8.20
May 24, 09:33:04 AM: Using PHP version 8.0
May 24, 09:33:04 AM: mise e[36m/opt/build/repo/mise.tomle[0m tools: e[34mpythone[0m@3.8.20
May 24, 09:33:04 AM: mise e[36m/opt/build/repo/mise.tomle[0m tools: e[34mpythone[0m@3.8.20
May 24, 09:33:04 AM: mise e[36m/opt/build/repo/mise.tomle[0m tools: e[34mpythone[0m@3.8.20
May 24, 09:33:04 AM: mise e[36m/opt/build/repo/mise.tomle[0m tools: e[34mpythone[0m@3.8.20
May 24, 09:33:04 AM: mise e[36m/opt/build/repo/mise.tomle[0m tools: e[34mpythone[0m@3.8.20
May 24, 09:33:05 AM: mise e[36m/opt/build/repo/mise.tomle[0m tools: e[34mpythone[0m@3.8.20
May 24, 09:33:06 AM: Downloading and installing node v20.19.2...
May 24, 09:33:06 AM: Downloading https://nodejs.org/dist/v20.19.2/node-v20.19.2-linux-x64.tar.xz...
May 24, 09:33:06 AM: Computing checksum with sha256sum
May 24, 09:33:06 AM: Checksums matched!
May 24, 09:33:09 AM: Now using node v20.19.2 (npm v10.8.2)
May 24, 09:33:09 AM: Enabling Node.js Corepack
May 24, 09:33:09 AM: Started restoring cached build plugins
May 24, 09:33:09 AM: Finished restoring cached build plugins
May 24, 09:33:09 AM: Started restoring cached corepack dependencies
May 24, 09:33:09 AM: Finished restoring cached corepack dependencies
May 24, 09:33:09 AM: No npm workspaces detected
May 24, 09:33:09 AM: Started restoring cached node modules
May 24, 09:33:09 AM: Finished restoring cached node modules
May 24, 09:33:09 AM: Installing npm packages using npm version 10.8.2
May 24, 09:33:12 AM: npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
May 24, 09:33:12 AM: npm warn deprecated rimraf@2.7.1: Rimraf versions prior to v4 are no longer supported
May 24, 09:33:13 AM: npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
May 24, 09:33:14 AM: npm warn deprecated @types/handlebars@4.1.0: This is a stub types definition. handlebars provides its own type definitions, so you do not need this installed.
May 24, 09:33:36 AM: added 739 packages, and audited 740 packages in 27s
May 24, 09:33:36 AM: 98 packages are looking for funding
May 24, 09:33:36 AM:   run `npm fund` for details
May 24, 09:33:36 AM: 2 vulnerabilities (1 low, 1 moderate)
May 24, 09:33:36 AM: To address issues that do not require attention, run:
May 24, 09:33:36 AM:   npm audit fix
May 24, 09:33:36 AM: To address all issues, run:
May 24, 09:33:36 AM:   npm audit fix --force
May 24, 09:33:36 AM: Run `npm audit` for details.
May 24, 09:33:36 AM: npm packages installed
May 24, 09:33:37 AM: Successfully installed dependencies
May 24, 09:33:37 AM: Starting dev server
May 24, 09:33:37 AM: mise e[36m/opt/build/repo/mise.tomle[0m tools: e[34mpythone[0m@3.8.20
May 24, 09:33:37 AM: mise e[36m/opt/build/repo/mise.tomle[0m tools: e[34mpythone[0m@3.8.20
May 24, 09:33:37 AM: mise e[36m/opt/build/repo/mise.tomle[0m tools: e[34mpythone[0m@3.8.20
May 24, 09:33:42 AM: ⬥ Setting up local dev server
May 24, 09:33:57 AM: [dev-server-plugin] listening on port 8288
May 24, 09:33:58 AM: e[32minfoe[39m: Site directory: /opt/build/repo
May 24, 09:33:58 AM: e[32minfoe[39m: Loading configuration from https://api-create.services.netlify.com
May 24, 09:33:58 AM: e[32minfoe[39m: localId: 390ce558cb594a0a8b13b4aff8c666cc
May 24, 09:33:59 AM: e[32minfoe[39m: Using Content Source Interface
May 24, 09:33:59 AM: ⬥ Starting Next.js dev server
May 24, 09:33:59 AM: e[33m⠋e[39m Waiting for Next.js dev server to be ready on port 3000
May 24, 09:33:59 AM: e[32m✔e[39m Next.js dev server ready on port 3000
May 24, 09:33:59 AM: ​
May 24, 09:33:59 AM: Summary
May 24, 09:33:59 AM: ────────────────────────────────────────────────────────────────
May 24, 09:33:59 AM: ​
May 24, 09:33:59 AM: ❯ @netlify/plugin-visual-editor: Visual Editor server started
May 24, 09:33:59 AM:    Open http://localhost:8888/_stackbit in your browser
May 24, 09:33:59 AM: Adding local .netlify folder to .gitignore file...
May 24, 09:33:59 AM:    ╭─────────────────────── ⬥  ────────────────────────╮
May 24, 09:33:59 AM:    │                                                   │
May 24, 09:33:59 AM:    │   Local dev server ready: http://localhost:8888   │
May 24, 09:33:59 AM:    │                                                   │
May 24, 09:33:59 AM:    ╰───────────────────────────────────────────────────╯
May 24, 09:34:00 AM: > nextn@0.1.0 dev
May 24, 09:34:00 AM: > node -r ./maxListeners.js --trace-warnings node_modules/.bin/next dev -p 9002
May 24, 09:34:00 AM: Setting EventEmitter.defaultMaxListeners to 100
May 24, 09:34:01 AM: Setting EventEmitter.defaultMaxListeners to 100
May 24, 09:34:01 AM: (node:5261) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 26 aborted listeners added to [IncomingMessage]. MaxListeners is 25. Use emitter.setMaxListeners() to increase limit
May 24, 09:34:01 AM: (Use `node --trace-warnings ...` to show where the warning was created)
May 24, 09:34:01 AM: (node:5261) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 26 error listeners added to [IncomingMessage]. MaxListeners is 25. Use emitter.setMaxListeners() to increase limit
May 24, 09:34:04 AM:    ▲ Next.js 15.2.3
May 24, 09:34:04 AM:    - Local:        http://localhost:9002
May 24, 09:34:04 AM:    - Network:      http://10.72.64.169:9002
May 24, 09:34:04 AM:  ✓ Starting...
May 24, 09:34:09 AM:  ✓ Ready in 6.6s
May 24, 09:34:51 AM: (node:5261) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 26 aborted listeners added to [IncomingMessage]. MaxListeners is 25. Use emitter.setMaxListeners() to increase limit
May 24, 09:34:51 AM: (node:5261) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 26 error listeners added to [IncomingMessage]. MaxListeners is 25. Use emitter.setMaxListeners() to increase limit
May 24, 09:35:43 AM: /opt/build-bin/run-build-functions.sh: line 1162:  5261 Killed                  "$@"
May 24, 09:35:43 AM: Error running command: exit status 137
May 24, 09:35:43 AM: Finished processing dev server in 2m51.325s
May 24, 09:35:43 AM: ==================================================================
May 24, 09:35:43 AM:
May 24, 09:35:45 AM: Building without cache
May 24, 09:35:45 AM:
May 24, 09:35:45 AM: devbot version: 824ae472ac144313f8511179632b58d4df7435cf
May 24, 09:35:45 AM: build-image version: 2be63b793c62ef8e32317f27dbcfe59c48c048e5 (focal)
May 24, 09:35:45 AM: Failed to check if ref preview exists
May 24, 09:35:45 AM: Starting to prepare your repo
May 24, 09:35:45 AM: ==================================================================
May 24, 09:35:45 AM: Finished processing dev server in 148ms```

Killed, looks like your container is running out of memory. You likely need more.