-
-
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: Prevent Engine.destroy test intermittent failure #12765
Open
mcmire
wants to merge
4
commits into
main
Choose a base branch
from
resolve-intermittent-engine-destroy-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+48
−0
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
+ 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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 plan on updating
@metamask/network-controller
with this change in another PR so we don't need this patch long-term.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.
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
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.
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.
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.
@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 :)
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've submitted a PR to fix this in NetworkController here: MetaMask/core#5116