react-native-examples icon indicating copy to clipboard operation
react-native-examples copied to clipboard

[bug]: MaxListenersExceededWarning: Possible EventEmitter memory leak detected

Open edenmeshulam opened this issue 2 years ago • 1 comments

Description

useEffect(() => {
    if (
      copyDialog ||
      approvalModal ||
      signTypedDataModal ||
      signModal ||
      sendTransactionModal
    ) {
      web3wallet.on('session_proposal', onSessionProposal);
      web3wallet.on('session_request', onSessionRequest);
    }
  }, [
    WCURI,
    approvalModal,
    copyDialog,
    signModal,
    signTypedDataModal,
    sendTransactionModal,
    requestEventData,
    requestSession,
    onSessionProposal,
    onSessionRequest,
    successPair,
  ]);

This code example is causing a multiple event listeners error, why do we need to call this event every state change? when I call that event once time after initializing it works well without the error, but after some messages are received the connect stops receiving messages and I need to restart the app.

Issue Environment

  • [ ] dapps/v2Explorer
  • [ ] wallets/rn_cli_wallet
  • [X] wallets/rn_cli_wallet_068_5
  • [ ] wallets/expo_wallet
  • [ ] wallets/web3wallet_tutorial
  • [X] In my own code

Output of npx react-native info

System: OS: macOS 13.4.1 CPU: (10) arm64 Apple M1 Pro Memory: 108.92 MB / 32.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 16.20.0 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 8.19.4 - /usr/local/bin/npm Watchman: 2023.09.04.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4 Android SDK: Not Found IDEs: Android Studio: 2022.1 AI-221.6008.13.2211.9514443 Xcode: 14.3.1/14E300c - /usr/bin/xcodebuild Languages: Java: 17.0.6 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: ^0.68.0 => 0.68.7

Steps to reproduce

Call the session_proposal and session_request events once only after the initialization. then call some message a couple of times and after some time it stops working,

Snack, code example, screenshot, or link to a repository

const onInitialize = useCallback(async () => {
    try {
      await createWeb3Wallet();
      if (web3wallet) {
        web3wallet.on('session_proposal', onSessionProposal);
        web3wallet.on('session_request', onSessionRequest);
        web3wallet.on('session_delete', onSessionDelete);
        setInitialized(true);
      }
    } catch (err: unknown) {
      console.log('Error for initializing', err);
    }
  }, []);

edenmeshulam avatar Sep 27 '23 09:09 edenmeshulam

Any news ?

edenmeshulam avatar Jan 14 '24 12:01 edenmeshulam

@edenmeshulam i think it's related to this: https://github.com/orgs/WalletConnect/discussions/3368#discussioncomment-6710452

Also, please check wallets/rn_cli_wallet implementation as it contains some refactors.

If its still happening, feel free to reach again with an MRE and we'll reopen this.

ignaciosantise avatar May 30 '24 13:05 ignaciosantise