-
Notifications
You must be signed in to change notification settings - Fork 2.3k
MaxListenersExceededWarning in more complex dapps #1942
Comments
Hm, it's tough to compare truffle-contract 4.x and 3.x, but it's useful information to know the problem goes back far and isn't something new we've broken. Not sure what might be causing it. Perhaps something with setting the provider. It looks like web3 beta.53 is getting released soon, fixing a number of breaking changes for Truffle, so we might be able to upgrade finally! I might suggest waiting for then to see if this problem sorts itself out, assuming the beta.53 upgrade is painless, unless anyone has ideas on what the underlying culprit here might be. Thanks for going through the effort to explain @wbt; your instructions will be very useful in validating a fix. It's hard to reliably reproduce this sort of thing. |
That is a big assumption and I am skeptical that it's warranted. Issues like the one logged here are blocking us from upgrading to truffle-contract 4.x and the new web3. Every time we try, it's about a week of headaches and extra work, finding there are still serious issues in the underlying software that wasn't actually ready for release, and then reversion. However, Beta.53 is now released, so the speculation of several hours ago is now a testable hypothesis. If Truffle upgrading to that can fix the issue, great!
Yes, I hope the instructions are helpful. That was multiple days of work, at the tail end of the most recent upgrade attempt. |
I'm more hopeful than previously because there has been a lot of active conversation over on web3's side lately. We've expressed the breaking changes we've identified since beta.37.
Here we go. Bet you ten finney that it fails the first time 😏 #1968 |
No way would I take the other side of that, even if I'd noticed before the test failure! |
What's going on here? Web3 beta.53 is clearly a no-go :) Any ideas @wbt? Thanks! |
I have no idea currently on what's going on to cause this bug, and am wanting to hold off on upgrading to any relatively recent version until it's fixed. I agree that it needs investigation, but invested quite a bit into making a good report including carefully building the steps to reproduce noted above, which don't take that long to walk through. I'd be quite disappointed if this were closed especially on a needs-reproduced basis. To others who try, please actively write a comment reporting your +1 below, until needs-reproduced is removed. |
Does this have anything to do with this? trufflesuite/ganache#267 (comment) |
@adrianmcli It might; nice find! The stack trace differs after a few lines, and that issue reports that Truffle suppressed (all?) upstream warnings in this PR on July 6, 2018. That suppression appears to be in Truffle v4.0.14 and later (it's still there) with a note that it was intended to be temporary until Web3 issue 1648 was resolved; that issue was closed unresolved with redirection to the open Ganache issue you linked to. The above was observed using MetaMask in a browser. I'm not an expert on how MetaMask selects a Provider, but I think it's an HTTP provider which happens to be pointing at an RPC interface on a Ganache node, rather than a Ganache-specific Provider being used. One way to see if it's specific to Ganache or not would be to run the above Steps to Reproduce as described (to verify that the issue is observed), and then rerun the migration and access steps on a different network (e.g. local geth or a testnet). If the issue is still observed anywhere else, it's definitely not Ganache-specific. |
@wbt yes, if you look at what @seesemichaelj said in that issue, he mentions that the real problem is in Web3.js because of how they attach listeners. Do check out this as well: web3/web3.js#1648 (comment) I'm pretty confident it's a problem with Web3.js. |
@adrianmcli I did read that and tentatively agree, but the Web3 issue was CLOSED WONTFIX by someone who's much more expert than I about that codebase. It remained closed even after comments by Levino et al. reporting that this was an issue with Web3 observed in the browser. So I suspect I might be missing something, or at least I'd want to spend more time diving into the codebase and getting more specific details before publicly asserting that @nivida is wrong on this topic where he is expert and I am not. Also, even if it is definitely an issue with Web3, I'm not optimistic that it will be fixed there, based on the status of the tracked issue. |
@wbt please see my latest comment there: web3/web3.js#1648 (comment) Since I am confident this is a Web3 problem, I will continue the investigation on that issue (even if it's closed). I can petition @nivida to open it up again. |
@wbt Is this issue still relevant? Let me know, thanks! |
@eggplantzzz I believe so. I don't see any particular reason to believe that it has been fixed, nor are there any plans to address a related issue from the Web3 side (web3#1648 remains CLOSED WONTFIX), and there is still a use case for having a dapp involving more than a few smart contracts. |
@wbt Ok sounds good! I'll look into it and thanks for the detailed report! |
@eggplantzzz this is an on-going problem. I believe it has something to do with the organizational structure of Web3.js, and its heavy reliance on OOP objects + EventEmitters (i.e. assigning listeners unnecessarily). |
@michaelsbradleyjr, do you know anything about this? |
@haltman-at I don't. But looking at the comment history of web3/web3.js#1648 it seems that issue may need to be reopened or a new one created. |
@michaelsbradleyjr @haltman-at Let's try to petition @nivida to re-open web3/web3.js#1648. |
We are marking this as blocked by web3 stuff. :) |
Hi @wbt is this issue still happening? We think it is probably resolved but wanted to check in. Thanks! |
@fainashalts Yes I believe it is, though it's blended into the background and become harder to notice. |
FYI I am still observing the issue today. |
Thanks for the update! Always helpful to know how current these are. |
Issue
In a more complex dapp with several smart contracts, truffle-contract v4.0.x produces a MaxListenersExceededWarning, reporting detection of a possible EventEmitter memory leak.
It appears the warning comes as result of a call to
setProvider()
on the TruffleContract object.Steps to Reproduce
Note: Not all of these are strictly necessary to reproduce the issue, but I believe they help with clarity and explanation and confidence that other factors are not affecting the outcomes.
npm uninstall truffle -g
.npm run dev
. This is done with truffle 5.0.13 (now the latest) being installed in the first step. You can skip most of the MetaMask setup if you’ve previously done it.contractName
to the functioninitContract
. Log it as a new first line in the function execution.$.getJSON
, replace'Adoption.json'
withcontractName+'.json'
return App.initContract();
with:initContract
, comment out the call tomarkAdopted()
.truffle compile
truffle migrate --reset
npm run dev
again.After the previously observed console outputs, there is a new warning:
npm uninstall truffle-contract
npm install [email protected]
npm list web3
(optional, to verify web3 version remains 1.0.0-beta.37)cp node_modules/truffle-contract/dist/truffle-contract.js src/js/truffle-contract.js
npm run dev
In 4.0.2, 4.0.1, and 4.0.0, web3 goes to beta.52, but there is not a minified version of beta.38 or later, and Trufflesuite’s fork of web3 doesn’t have beta.37 or after. The specification is "^1.0.0-beta.37", so sticking with 37 seems best.
In 4.0.0 and 4.0.1 there are various other errors instead, starting with “Uncaught TypeError: EthersAbi is not a constructor” (Issue #1619).
npm show truffle-contract@3.* version
shows 3.0.{0-7} as options.npm uninstall truffle-contract
.npm install [email protected]
.cp node_modules/truffle-contract/dist/truffle-contract.js src/js/truffle-contract.js
npm list web3
shows 0.20.6.wget https://raw.githubusercontent.com/ethereum/web3.js/v0.20.6/dist/web3.min.js -OutFile src/js/web3.min.js
npm run dev
and now we’re back to step 15 without warning messages.Expected Behavior
No MaxListenersExceededWarning and no memory leak. Clarity in the warning message about whether subsequent listeners are getting created/attached properly or what other consequences might be, since a programmer adapting prior code for compatibility with newer versions of Truffle is not explicitly using listeners, and may find this warning confusing.
Environment
truffle version
): 5.0.13node --version
): 9.3.0npm --version
): 6.9.0Additional information
Addressing issue 1938 could help make debugging this and similar future issues easier.
The text was updated successfully, but these errors were encountered: