Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gatsby develop causes MaxListenersExceededWarning resource drain #5510

Closed
jeffwillette opened this issue May 22, 2018 · 10 comments · Fixed by #10593
Closed

gatsby develop causes MaxListenersExceededWarning resource drain #5510

jeffwillette opened this issue May 22, 2018 · 10 comments · Fixed by #10593

Comments

@jeffwillette
Copy link
Contributor

jeffwillette commented May 22, 2018

Description

when I run gatsby develop, after editing a few files and having it recompile I eventually get the error.

(node:47) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 drain listeners added. Use emitter.setMaxListeners() to increase limit

Steps to reproduce

On my machine in my project, I just run develop and continue editing files. I have not been able to reproduce in a sample project yet. I have used a tool to get a stack trace out of the warning and it lists this

Error: too many listeners of type "drain" added to EventEmitter. Max is 10 and we've added 11.
    at Queue.newAddListener (/frontend/node_modules/throw-max-listeners-error/index.js:12:17)
    at /frontend/node_modules/gatsby/dist/internal-plugins/query-runner/page-query-runner.js:170:11
    at initializePromise (/frontend/node_modules/es6-promise/dist/es6-promise.js:459:5)
    at new Promise (/frontend/node_modules/es6-promise/dist/es6-promise.js:871:31)
    at runQueriesForIds (/frontend/node_modules/gatsby/dist/internal-plugins/query-runner/page-query-runner.js:169:10)
    at _callee2$ (/frontend/node_modules/gatsby/dist/internal-plugins/query-runner/page-query-runner.js:102:20)
    at tryCatch (/frontend/node_modules/regenerator-runtime/runtime.js:62:40)
    at Generator.invoke [as _invoke] (/frontend/node_modules/regenerator-runtime/runtime.js:296:22)
    at Generator.prototype.(anonymous function) [as next] (/frontend/node_modules/regenerator-runtime/runtime.js:114:21)
    at step (/frontend/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
    at /frontend/node_modules/babel-runtime/helpers/asyncToGenerator.js:35:14
    at new Promise (/frontend/node_modules/core-js/library/modules/es6.promise.js:177:7)
    at /frontend/node_modules/babel-runtime/helpers/asyncToGenerator.js:14:12
    at runQueuedActions (/frontend/node_modules/gatsby/dist/internal-plugins/query-runner/page-query-runner.js:122:18)
    at /frontend/node_modules/mitt/dist/mitt.js:1:268
    at Array.map (<anonymous>)
(node:47) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 drain listeners added. Use emitter.setMaxListeners() to increase limit

Expected result

the standard behavior

Actual result

Computer resources are all maxed out and my machine becomes very laggy and

Environment

  • Gatsby version (npm list gatsby): gatsby@1.9.261
  • gatsby-cli version (gatsby --version): 1.9.261
  • Node.js version: v10.1.0
  • Operating System: OSSierra 10.13.4

File contents (if changed)

gatsby-config.js: N/A
package.json: N/A
gatsby-node.js: N/A
gatsby-browser.js: N/A
gatsby-ssr.js: N/A

@jeffwillette
Copy link
Contributor Author

I have managed to whittle my whole project down to almost nothing, just an index page and a basic gatsby-node and one template. I get the issue when I start the dev server and then edit a file and save 10-15 times.

I have been editing the pages index with just one letter and saving and undoing.

https://github.com/deltaskelta/gatsby-issue-5510

@ryanditjia
Copy link
Contributor

I was able to reproduce, then I tried changing this line:

gatsby-config.js

path: `${__dirname}/src/`

to

path: `${__dirname}/src/pages/tips`

and it seems to fix the problem. Perhaps because both Gatsby and its plugin recognize there’s been a change to one of its files (I was editing pages/index.js), and end causing a circular reference.

I recommend putting your data files out of src, similar to how Gatsby’s site does it.

@jeffwillette
Copy link
Contributor Author

hmm nice find... :)

If that is the case how would I handle multiple pages that have markdown files? I have eliminated the rest for the example, but I have many more dirs than just tips that I need checked

@jeffwillette
Copy link
Contributor Author

I missed the last line of your comment, I guess I can pull all of them out and put them in dirs corresponding to their page.

@jeffwillette
Copy link
Contributor Author

closing for now, will reopen if it reappears when I try to test the solution. Thanks

@jeffwillette
Copy link
Contributor Author

FWIW, the warning still occurs, but I do not get the system drain that happened before

@ryanditjia
Copy link
Contributor

Not sure if this helps, but I also removed the line:

import { graphql } from 'react-apollo'

Because I thought that could affect Gatsby’s graphql query.

Maybe you can differentiate the one from apollo by aliasing the destructured import?

import { graphql as apollographql } from 'react-apollo'

@jeffwillette
Copy link
Contributor Author

another good catch. I'm using an import tool so it must have just imported from apollo without me noticing. I'll change it to gatsby's and see if it disappears

@wangpin34
Copy link

Found the error while executing the build process.

17:00:22  error (node:26309) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added to [process]. Use emitter.setMaxListeners() to increase limit
17:00:22  error (node:26309) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added to [process]. Use emitter.setMaxListeners() to increase limit
17:00:22  error (node:26309) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGTERM listeners added to [process]. Use emitter.setMaxListeners() to increase limit
17:00:22  error (node:26309) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGHUP listeners added to [process]. Use emitter.setMaxListeners() to increase limit

It looks like the above errors don't abort the process. However, it still makes me feel upset.

scottdiemer added a commit to scottdiemer/gatsby-portfolio that referenced this issue Jan 11, 2022
@TomaszWaszczyk
Copy link

TomaszWaszczyk commented Apr 23, 2024

Same here, anyone has solved the issue?

@ryanditjia Do you have maybe explanation what is wrong with having data in src?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants