-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix: Fix console errors upon switching networks #7278
Conversation
86670ea
to
6f35519
Compare
On `main` two warnings were printed to the console repeatedly after switching networks. They were: * Error: Callback was already called. Possible Unhandled Promise Rejection * MaxListenersExceededWarning: Possible EventEmitter memory leak detected ... This started happening after PR #6872. If you look at network traffic, you could see that this lines up with extra network calls being made to the previous network as well (the `eth_getBlockByNumber` method specifically). These warnings were caused by a change made in `@metamask/network-controller@6.0.0`, which was to proxy the provider and block tracker. This introduced an incompatibility between the `NetworkController` and `web3-provider-engine`, which was still using the unproxied block tracker. `web3-provider-engine` adds an event listener on the `latest` event from the block tracker, which calls `eth_getBlockByNumber` with a retry. This listener was migrated to the new network after switching, but would make that RPC call on the old provider. The user effects of this are an increase in unnecessary network traffic, but is otherwise harmless. The `web3-provider-engine` package has been patched to make the block tracker event listener into a no-op after the provider has been stopped. This isn't an ideal solution as it still leaves the listener attached, which is a small memory leak. But it resolves the warnings and prevents the unnecessary network calls. We will be updating to `@metamask/network-controller` v9 soon which will resolve this problem permanently by removing `web3-provider-engine`. Fixes #7082
6f35519
to
6ca5cda
Compare
Passing E2E smoke test run: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/096eddd8-e5a5-4eee-8e68-b4e1e388670c |
Codecov ReportPatch and project coverage have no change.
Additional details and impacted files@@ Coverage Diff @@
## main #7278 +/- ##
=======================================
Coverage 34.43% 34.43%
=======================================
Files 1016 1016
Lines 27087 27087
Branches 2206 2206
=======================================
Hits 9327 9327
Misses 17267 17267
Partials 493 493 ☔ View full report in Codecov by Sentry. |
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just verified that there are no more warnings
Description
On
main
two warnings were printed to the console repeatedly after switching networks. They were:This started happening after PR #6872. If you look at network traffic, you could see that this lines up with extra network calls being made to the previous network as well (the
eth_getBlockByNumber
method specifically).These warnings were caused by a change made in
@metamask/network-controller@6.0.0
, which was to proxy the provider and block tracker. This introduced an incompatibility between theNetworkController
andweb3-provider-engine
, which was still using the unproxied block tracker.web3-provider-engine
adds an event listener on thelatest
event from the block tracker, which callseth_getBlockByNumber
with a retry. This listener was migrated to the new network after switching, but would make that RPC call on the old provider.The user effects of this are an increase in unnecessary network traffic, but is otherwise harmless.
The
web3-provider-engine
package has been patched to make the block tracker event listener into a no-op after the provider has been stopped. This isn't an ideal solution as it still leaves the listener attached, which is a small memory leak. But it resolves the warnings and prevents the unnecessary network calls. We will be updating to@metamask/network-controller
v9 soon which will resolve this problem permanently by removingweb3-provider-engine
.Manual testing steps
yarn watch
console output)Screenshots/Recordings
Before
https://recordit.co/SXZf4Vhnbz
After
https://recordit.co/5CIOzb4srH
Related issues
Fixes #7082
Pre-merge author checklist
Pre-merge reviewer checklist