Skip to content

Fix 9632 - Prevent old fetches from polluting the swap state#9671

Merged
darkwing merged 1 commit intoMetaMask:developfrom
darkwing:9632-simple-abort
Oct 26, 2020
Merged

Fix 9632 - Prevent old fetches from polluting the swap state#9671
darkwing merged 1 commit intoMetaMask:developfrom
darkwing:9632-simple-abort

Conversation

@darkwing
Copy link
Copy Markdown
Contributor

No description provided.

@darkwing darkwing requested a review from a team as a code owner October 21, 2020 20:13
@darkwing darkwing requested review from danjm and whymarrh October 21, 2020 20:13
@github-actions
Copy link
Copy Markdown
Contributor

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.

@darkwing
Copy link
Copy Markdown
Contributor Author

Seeing this error, looking into it:

FetchError

Copy link
Copy Markdown
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

Note that we do have a polyfill already for AbortController, so we can cancel any in-flight requests using that.

We use this in app/scripts/lib/fetch-with-timeout.js for example.

@danjm
Copy link
Copy Markdown
Contributor

danjm commented Oct 22, 2020

@Gudahtt Yeah, David did implement a solution that used AbortController, you can see it here: deaf1b5

We looked at it together, and the challenge is aborting all the async calls that happen after that first fetch. For instance, aborting await this.timedoutGasReturn(Object.values(newQuotes)[0].approvalNeeded) would be a big challenge, I think? At least, we'd have to get the signal passed through createInfuraMiddleware to the fetch ultimately called in https://github.com/MetaMask/eth-json-rpc-infura/blob/master/src/index.js This would require signal to be serializable, which I don't think it is, or some way to update the infura middleware config after initialization.

Given that not all the async calls here can be aborted, the least we can do is the minimum necessary change of preventing a state update after the calls are complete.

@danjm
Copy link
Copy Markdown
Contributor

danjm commented Oct 22, 2020

@darkwing Regarding that error, some additional changes are needed so that fetchQuotesAndSetQuoteState in ducks/swaps/swaps, which calls SwapsController.fetchAndSetQuotes, can properly handle the response in the case of this.indexOfNewestCallInFlight !== indexOfCurrentCall

One option would be to throw an error with a custom message, and then check for that message in the catch in fetchQuotesAndSetQuoteState and respond accordingly.

@danjm
Copy link
Copy Markdown
Contributor

danjm commented Oct 23, 2020

All the code here is looking good and the initial QA is almost perfect. There was some weird behaviour that I saw when radpidly going back and forth between the build quote and loading screen. I think that might be a pre-existing issue though. I am going to QA one more time a little later, and then we should be able to merge this.

Copy link
Copy Markdown
Contributor

@danjm danjm left a comment

Choose a reason for hiding this comment

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

Final QA looks good. Approved.

@darkwing darkwing merged commit 6e89b60 into MetaMask:develop Oct 26, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Oct 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants