Skip to content
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: Prevent Engine.destroy test intermittent failure #12765

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions patches/@metamask+network-controller+22.1.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
diff --git a/node_modules/@metamask/network-controller/dist/NetworkController.cjs b/node_modules/@metamask/network-controller/dist/NetworkController.cjs
index cc9793f..e7334e4 100644
--- a/node_modules/@metamask/network-controller/dist/NetworkController.cjs
+++ b/node_modules/@metamask/network-controller/dist/NetworkController.cjs
@@ -525,7 +525,20 @@ class NetworkController extends base_controller_1.BaseController {
let networkChanged = false;
const listener = () => {
networkChanged = true;
- this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I plan on updating @metamask/network-controller with this change in another PR so we don't need this patch long-term.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we handle this upstream instead, and fix it here by updating? It looks like we're on the latest major version, so it should be relatively easy to do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be better for sure. I don't have a lot of time today and just wanted to get this person unblocked for the time being or at least give them a solution they can use to complete their draft PR, but I can make a change upstream later today or possibly tomorrow.

Copy link
Contributor

@mathieuartu mathieuartu Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mcmire , don't stress yourself over this! While I really appreciate the effort to unblock me (🫶), this was only a draft PR to test a core change that I'm planning to merge later this week. The extension draft PR in itself will be closed. I'd rather go with the classic update flow instead of adding a patch as well, so let's take our time to do this :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've submitted a PR to fix this in NetworkController here: MetaMask/core#5116

+ try {
+ this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
+ } catch (error) {
+ if (
+ typeof error === 'object' &&
+ error !== null &&
+ 'message' in error &&
+ error.message === 'Subscription not found for event: NetworkController:networkDidChange'
+ ) {
+ // The controller may have been destroyed, so don't worry about it
+ } else {
+ throw error;
+ }
+ }
};
this.messagingSystem.subscribe('NetworkController:networkDidChange', listener);
let updatedNetworkStatus;
@@ -575,7 +588,20 @@ class NetworkController extends base_controller_1.BaseController {
// in the process of being called, so we don't need to go further.
return;
}
- this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
+ try {
+ this.messagingSystem.unsubscribe('NetworkController:networkDidChange', listener);
+ } catch (error) {
+ if (
+ typeof error === 'object' &&
+ error !== null &&
+ 'message' in error &&
+ error.message === 'Subscription not found for event: NetworkController:networkDidChange'
+ ) {
+ // The controller may have been destroyed, so don't worry about it
+ } else {
+ throw error;
+ }
+ }
this.update((state) => {
const meta = state.networksMetadata[state.selectedNetworkClientId];
meta.status = updatedNetworkStatus;
Loading