-
Notifications
You must be signed in to change notification settings - Fork 5k
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: setupControllerConnection outstream end event listener #26141
fix: setupControllerConnection outstream end event listener #26141
Conversation
…ection in metamask-controller.js is called when it should be
…requests to infura after the UI has closed
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
privacy-snapshot.json
Outdated
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.
For a later PR: We should consider sorting this with prettier (prettier-plugin-sort-json
can do it)
This comment was marked as resolved.
This comment was marked as resolved.
]; | ||
} | ||
|
||
async function getAllInfuraJsonRpcRequests( |
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.
This looks nice and like it could be useful elsewhere!
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.
+1!
…r needed privacy snapshot addition
mockedEndpoint, | ||
); | ||
|
||
await driver.openNewURL('chrome://extensions'); |
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.
It looks like this makes the firefox test fail. Could we selectively go to:
await driver.openNewURL('chrome://extensions'); | |
if (process.env.SELENIUM_BROWSER === 'chrome') { | |
await driver.openNewURL('chrome://extensions'); | |
} else if (process.env.SELENIUM_BROWSER === 'firefox') { | |
await driver.openNewURL('about:debugging#/runtime/this-firefox'); | |
} |
or something similar? This solves the issue in my end
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.
I fixed it by replacing the url with about:blank
a315444
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.
oh nice 😍 ty!!
} | ||
|
||
describe('Account Tracker API Usage', function () { | ||
it('should not make eth_call or eth_getBalance requests before the UI is opened and should make those requests after the UI is opened', async function () { |
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.
I see that the account tracker is also responsible from initiating eth_getBlockByNumber
calls. Should we also include them here?
account-tracker-getblockbynumber.mp4
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.
good suggestion, added here ac50f66
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.
thank you Dan, great refactor! Could it be that we are missing it here and in the test description (not a blocker though)?
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.
No, in that case there is an eth_getBlockbyNumber call before the UI opens, for other reasons. That should be addressed separately.
I will create a ticket for that and add a code comment and update the test description
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.
oh gotcha, thank you Dan!
Builds ready [a315444]
Page Load Metrics (412 ± 325 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #26141 +/- ##
===========================================
+ Coverage 69.94% 69.95% +0.01%
===========================================
Files 1409 1409
Lines 49794 49799 +5
Branches 13773 13771 -2
===========================================
+ Hits 34826 34832 +6
+ Misses 14968 14967 -1 ☔ View full report in Codecov by Sentry. |
Builds ready [98a10a1]
Page Load Metrics (63 ± 8 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
QA test OK ! |
); | ||
|
||
await driver.openNewURL('about:blank'); | ||
await driver.delay(20000); |
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.
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.
we need this to be 20000 ms long. I have added a code comment to explain 27df50c
7a00c1f
to
27df50c
Compare
Quality Gate passedIssues Measures |
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.
tests look good, though might be good to have a dev approval too, for the controllers change
Builds ready [27df50c]
Page Load Metrics (218 ± 212 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Missing release label release-12.0.0 on PR. Adding release label release-12.0.0 on PR and removing other release labels(release-12.4.0), as PR was cherry-picked in branch 12.0.0. |
Description
This PR addresses a problem which had the following surface level symptoms: when the UI is closed, the extension continues to send network requests to the provider.
Upon some investigation, we discovered that these requests were the result of polling initiated from the account tracker. And then upon further investigation, we discovered that the callback in the
outstream
'end'
listener insetupControllerConnection
ofmetamask-controller.js
was not being called when the UI was closed.This problem was introduced with #24533. That PR updates the
object-multiplex
dependency to v2.0.0. The major change in that update is the update of thereadable-stream
dependency from a v2 version to a v3 version. With that update, we see newpremature-close
errors in the background. It seems that these errors are still present in v2, but they are handled differently, resulting in an'error'
event instead of an'end'
event. We still have not established a definitive understanding of why this is happening, and follow up investigation will be needed.However, this PR still puts forward a fix that safely resolves the issue. The solution added here is to make use of the
readableStream.finished
function. The callback passed to this function will be called when the stream is ended. This function has the same behaviour as theoutstream.on('end'
listener had prior to the aforementioned PR.Instead of fully replacing the existing listener, we have added the
readableStream.finished
call in addition to the existing listener. The reason for this is explained in a code comment:To achieve "Logic has been added to the handler to ensure that calling it more than once does not have any affect.", the PR adds a unique id to each stream passed to
setupControllerConnection
, and uses aSet
to ensure the handler code only runs once per stream.This PR then adds automated tests. The added unit tests are focused on validating both pre-existing and new behaviour of
setupControllerChanged
. The added e2e tests focus on the inititially mentioned surface level symptoms: it confirms thateth_call
andeth_getBalance
calls, the calls coming from the account-tracker initiated polling, are not continued after the UI is closed. This e2e test fails on current develop but passes on this branch.MetaMask team members can see more details in this thread: https://consensys.slack.com/archives/CTQAGKY5V/p1721653870583869
Related issues
Fixes: #26002
Manual testing steps
To observe the bug on develop:
eth_call
andeth_getBalance
requests to infuraOn this branch, in step 4, after closing the UI, those requests will not continue.
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist