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

feat: Expire duplicate RPC requests after three minutes #24487

Merged
merged 8 commits into from May 20, 2024

Conversation

rekmarks
Copy link
Member

@rekmarks rekmarks commented May 10, 2024

Description

Flushes the memorized request ids in the duplicate request middleware every 3 minutes, and makes the middleware ignore JSON-RPC notifications. Also converts the middleware to TypeScript.

The duplicate request middleware used to dedupe JSON-RPC requests with the same id under MV3 used an internal array that would grow boundlessly until the background restarted. In addition, this middleware assumed that it would never see any JSON-RPC notifications (or it would always reject the n + 1:th notifications, since their ids are always undefined). Although we in practice always add ids to JSON-RPC requests, it seems ill-advised for this middleware to make that assumption.

Open in GitHub Codespaces

Related issues

N/A

Manual testing steps

  1. Build the extension under MV3
  2. Ensure that RPC requests are working correctly

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've completed the PR template to the best of my ability
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

return;
}

const cutoffTime = Date.now() - FIVE_MINUTES;
Copy link
Member Author

Choose a reason for hiding this comment

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

I picked five minutes because it seems extremely unlikely that we'd receive an actually duplicate request id in that timespan. Curious if we could go with an even shorter timespan, but I would need guidance from someone more familiar with MV3.

@metamaskbot
Copy link
Collaborator

Builds ready [9685326]
Page Load Metrics (1056 ± 647 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint68177962713
domContentLoaded10321563
load56300310561347647
domInteractive10321563
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 325 Bytes (0.01%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link

codecov bot commented May 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.46%. Comparing base (55d364d) to head (2483ec7).

Current head 2483ec7 differs from pull request most recent head b9edceb

Please upload reports for the commit b9edceb to get more accurate results.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #24487      +/-   ##
===========================================
+ Coverage    67.38%   67.46%   +0.08%     
===========================================
  Files         1289     1289              
  Lines        50235    50263      +28     
  Branches     13008    13024      +16     
===========================================
+ Hits         33849    33906      +57     
+ Misses       16386    16357      -29     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@legobeat
Copy link
Contributor

legobeat commented May 13, 2024

Can the typescript conversion be split out in a separate PR, preceding the rest of the changes in this one?

@rekmarks
Copy link
Member Author

Can the typescript conversion be split out in a separate PR, preceding the rest of the changes in this one?

@legobeat I don't think a separate PR is worth our time, but I split the initial migration out into its own commit: b029bb6

@rekmarks rekmarks changed the title feat: Expire duplicate RPC requests after five minutes feat: Expire duplicate RPC requests after three minutes May 14, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [2483ec7]
Page Load Metrics (951 ± 579 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint57150972713
domContentLoaded96918147
load4627779511207579
domInteractive96918147
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 365 Bytes (0.01%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

adonesky1
adonesky1 previously approved these changes May 20, 2024
Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

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

LGTM

@metamaskbot
Copy link
Collaborator

Builds ready [861e299]
Page Load Metrics (1311 ± 540 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint721731092914
domContentLoaded96221168
load60266013111125540
domInteractive96221168
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 358 Bytes (0.01%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@rekmarks rekmarks merged commit 43eac4b into develop May 20, 2024
71 of 72 checks passed
@rekmarks rekmarks deleted the rekm/bounded-dupe-reqs branch May 20, 2024 22:44
@github-actions github-actions bot locked and limited conversation to collaborators May 20, 2024
@metamaskbot metamaskbot added the release-11.18.0 Issue or pull request that will be included in release 11.18.0 label May 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
INVALID-PR-TEMPLATE PR's body doesn't match template release-11.18.0 Issue or pull request that will be included in release 11.18.0 team-extension-platform team-wallet-api-platform
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants