Memory leak detected issue

System Information
  • Strapi Version: 3.2.4
  • Operating System: macOS High Sierra 10.13.6
  • Database: SQLite 5.0.0, PostgreSQL 8.4.1
  • Node Version: 12.18.4
  • NPM Version: >=6.0.0
  • Yarn Version: 1.22.4

I installed a node package date-streaks to my app successfully, but when starting server again, got an error that Cannot find module 'strapi-utils'. Decided to uninstall the package, it uninstalled fine, but after that, starting up my server again gives this warning:

(node:6099) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unpipe listeners added to [WriteStream]. Use emitter.setMaxListeners() to increase limit

Doing node --trace-warnings, I got these:

Warning: MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unpipe listeners added to [WriteStream]. Use emitter.setMaxListeners() to increase limit
    at repl:1:9
    at Script.runInThisContext (vm.js:120:18)
    at REPLServer.defaultEval (repl.js:433:29)
    at bound (domain.js:427:14)
    at REPLServer.runBound [as eval] (domain.js:440:12)
    at REPLServer.onLine (repl.js:760:10)
    at REPLServer.emit (events.js:327:22)
    at REPLServer.EventEmitter.emit (domain.js:483:12)
    at REPLServer.Interface._onLine (readline.js:329:10)
    at REPLServer.Interface._line (readline.js:658:8)

Most of the .js files seems to be coming from /node_modules/pretty-error/:

module.exports = [
  '_debugger.js'
  '_http_agent.js'
  '_http_client.js'
  '_http_common.js'
  '_http_incoming.js'
  '_http_outgoing.js'
  '_http_server.js'
  '_linklist.js'
  '_stream_duplex.js'
  '_stream_passthrough.js'
  '_stream_readable.js'
  '_stream_transform.js'
  '_stream_writable.js'
  '_tls_legacy.js'
  '_tls_wrap.js'
  'assert.js'
  'buffer.js'
  'child_process.js'
  'cluster.js'
  'console.js'
  'constants.js'
  'crypto.js'
  'dgram.js'
  'dns.js'
  'domain.js'
  'events.js'
  'freelist.js'
  'fs.js'
  'http.js'
  'https.js'
  'module.js'
  'net.js'
  'os.js'
  'path.js'
  'punycode.js'
  'querystring.js'
  'readline.js'
  'repl.js'
  'smalloc.js'
  'stream.js'
  'string_decoder.js'
  'sys.js'
  'timers.js'
  'tls.js'
  'tty.js'
  'url.js'
  'util.js'
  'vm.js'
  'zlib.js'
  'node.js'
]

I researched on Stack Overflow, but still unsure where the issue is and which file I need to fix.

Where do I even start to debug this? Any general advice appreciated!

Can you please try wiping your:

  • .cache
  • build
  • node_modules
  • package-lock.json
  • yarn.lock

files/folders, then reinstall the node modules with either yarn install or npm install and rebuild/restart the Strapi server.

If that doesn’t work, can you try providing a sample project where you can reproduce the issue?

4 Likes

It worked!!! Oh gosh, such a simple solution. Amazed that there’s not one mention of trying this in Stack Overflow. Thanks so much @DMehaffy ! :laughing:

1 Like

Worked for me too! Thanks mate!

There used to be, we stopped using/recommending Stack Overflow because people were asking questions, getting their answer, then deleting their question.

That is actually one of the driving forces behind why we decided to start our own dedicated forum. :wink:

I do my best to avoid Stack Overflow when I can.

2 Likes

I was upgrading our strapi dependencies from 3.6.8 to 3.6.10 before making the leap to v4.

We have 15 strapi related dependencies altogether in our project:

    "strapi": "3.6.8",
    "strapi-admin": "3.6.8",
    "strapi-connector-bookshelf": "3.6.8",
    "strapi-hook-algolia": "^3.8.0",
    "strapi-plugin-content-manager": "3.6.8",
    "strapi-plugin-content-type-builder": "3.6.8",
    "strapi-plugin-email": "3.6.8",
    "strapi-plugin-i18n": "3.6.8",
    "strapi-plugin-oembed": "^0.4.0",
    "strapi-plugin-sentry": "^3.6.5",
    "strapi-plugin-upload": "3.6.8",
    "strapi-plugin-users-permissions": "3.6.8",
    "strapi-provider-email-mcmandrill": "file:providers/strapi-provider-email-mcmandrill",
    "strapi-provider-upload-canto": "file:providers/strapi-provider-upload-canto",
    "strapi-utils": "3.6.8"

I upgraded every dependency one by one and started strapi after each dependency. The moment I upgraded strapi-utils from 3.6.8 to 3.6.10, I got warnings similar to the ones by the OP:

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

First I deleted the .cache, build and node_modules folder and re-installed the dependencies.
Then, after starting strapi again, I received the warning again.

Only after I deleted the package-lock.json as well (which I originally wanted to avoid because now I get unfixed versions for my first- and third-party dependencies) and re-installed the dependencies, then upon starting strapi again, the warning was gone.

Now I’m sitting here, trying to figure out if I can live with that fix or if I should invest some time and energy to find out which of the countless transitive dependencies fixed in the package-lock.json is causing problems in my environment :smiley:

i tried on y developer server to delete all as above but still on deployment to the server i get this error, any ideas?
i tried to create new web service and its working but im not able to update with new commits because of this error