App: [HOLD for payment 2023-10-10] [$500] MaxListenersExceededWarning: Possible EventEmitter memory leak detected

This has been showing for over 2 months on dev. Can we fix it?

events.js:46 MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 onKeyCommand listeners added. Use emitter.setMaxListeners() to increase limit
    at _addListener (webpack-internal:///./node_modules/events/events.js:211:15)
    at EventEmitter.addListener (webpack-internal:///./node_modules/events/events.js:227:10)
    at EventEmitter.addListener (webpack-internal:///./node_modules/react-native-key-command/lib/module/KeyCommand/index.js:20:16)
    at Module.addListener (webpack-internal:///./node_modules/react-native-key-command/lib/module/index.js:110:30)
    at eval (webpack-internal:///./src/libs/KeyboardShortcut/index.js:84:57)
    at Function.each (webpack-internal:///./node_modules/underscore/modules/each.js:26:7)
    at eval (webpack-internal:///./src/libs/KeyboardShortcut/index.js:77:52)
    at ./src/libs/KeyboardShortcut/index.js (http://localhost:8082/main-8a767871f57b57b1baee.bundle.js:8113:1)
    at __webpack_require__ (http://localhost:8082/runtime-17296f4671db2b0d6f5f.bundle.js:36:33)
    at fn (http://localhost:8082/runtime-17296f4671db2b0d6f5f.bundle.js:352:21)

2023-09-07_09-50-01

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01961f084c190662b2
  • Upwork Job ID: 1701152779444531200
  • Last Price Increase: 2023-09-11
  • Automatic offers:
    • hungvu193 | Contributor | 26743727

Slack convo if necessary: https://expensify.slack.com/archives/C049HHMV9SM/p1694421370612589

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Comments: 36 (19 by maintainers)

Most upvoted comments

Just made the request.

We don’t have to add any test case and we can skip the checklist. We can’t call it a regression.

Summary of payments for this issue:

Upwork job: https://www.upwork.com/en-gb/jobs/~01961f084c190662b2

hey, I think we found out why this is happening.

We’re adding a new event listener everytime you access a report, and never removing those. So over time, if you access 10s of reports, it will pass the default limit from the browser.

I think we need to hold this a bit

Proposal

Please re-state the problem that we are trying to solve in this issue.

MaxListenersExceededWarning: Possible EventEmitter memory leak detected

What is the root cause of that problem?

We’re using events for EventEmitter which limit the listener to 10.

What changes do you think we should make in order to solve the problem?

The events library is a little bit outdated, we can upgrade it to use eventemitter3 which is faster and there’s no limit for listener. https://github.com/Expensify/react-native-key-command/blob/8e91f6d9381325eacbfd316a0baed496b29a2f22/src/KeyCommand/index.js#L4

import Events from 'eventemitter3';

const EventEmitter = new Events();

I created a fork and tested, it seemed that everything worked as expected (https://github.com/hungvu193/App/tree/bump-to-ee3).

What alternative solutions did you explore? (Optional)

N/A