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: Handle error when offscreen document already exists #25138

Merged
merged 2 commits into from
Jul 18, 2024

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Jun 7, 2024

Description

A try..catch block has been added to catch errors about the Offscreen document already existing. This circumstance is not a bug, it's expected to happen sometimes due to race conditions between hasDocument and the creation step. The code in question is just meant to create the document if it doesn't exist, so it's OK if we get this error.

The hasDocument call has been removed as well, since it's now redundant. This function wasn't safe to call anyway; it's an undocumented private function.

See here for more information:

Open in GitHub Codespaces

Related issues

Fixes #25118

Manual testing steps

I do not know how to test this unfortunately.

Screenshots/Recordings

N/A

Pre-merge author checklist

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.

@Gudahtt Gudahtt force-pushed the handle-offscreen-document-already-exists-error branch from 9ce1a35 to c00e8f7 Compare June 7, 2024 12:42
@Gudahtt Gudahtt marked this pull request as ready for review June 7, 2024 12:42
@Gudahtt Gudahtt requested a review from a team as a code owner June 7, 2024 12:42
@Gudahtt
Copy link
Member Author

Gudahtt commented Jun 7, 2024

I can't write unit tests for this file directly, not easily at least, because it has side-effects. I could move this function (and maybe some others) into a separate module and write unit tests for them there. Probably we should do this at some point. But there is minimal value in doing so because the logic here is so simple. Really it's the chrome extension API behavior that would be valuable to test; if we're mocking that, we're not really validating this fix.

That means a valuable test would have to be an e2e or manual test. But I don't know how to trigger the race condition where we attempt to create the offscreen document when it already exists.

@danjm danjm force-pushed the handle-offscreen-document-already-exists-error branch from c00e8f7 to f3d8360 Compare June 7, 2024 14:27
Copy link
Contributor

github-actions bot commented Jun 7, 2024

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.

@danjm

This comment was marked as resolved.

@Gudahtt Gudahtt force-pushed the handle-offscreen-document-already-exists-error branch from f3d8360 to 1594c48 Compare June 7, 2024 15:16
davidmurdoch
davidmurdoch previously approved these changes Jun 7, 2024
danjm
danjm previously approved these changes Jun 7, 2024
@Gudahtt
Copy link
Member Author

Gudahtt commented Jun 7, 2024

Still investigating the remaining e2e test error. It's a pre-existing flaky test, but something about this PR appears to make it fail more often (possibly every time)

@Gudahtt Gudahtt marked this pull request as draft June 10, 2024 12:46
@Gudahtt Gudahtt force-pushed the handle-offscreen-document-already-exists-error branch from c1e41a7 to 3397a77 Compare June 17, 2024 15:32
@Gudahtt Gudahtt marked this pull request as ready for review June 17, 2024 15:32
@Gudahtt
Copy link
Member Author

Gudahtt commented Jun 17, 2024

The test failures on this PR were resolved by #25164

Copy link

codecov bot commented Jun 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.44%. Comparing base (fcb4265) to head (ffb2c3a).
Report is 10 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #25138   +/-   ##
========================================
  Coverage    70.44%   70.44%           
========================================
  Files         1274     1274           
  Lines        44080    44080           
  Branches     12453    12453           
========================================
  Hits         31051    31051           
  Misses       13029    13029           

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

@metamaskbot
Copy link
Collaborator

Builds ready [3397a77]
Page Load Metrics (129 ± 174 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint68937863
domContentLoaded9121111
load401704129361174
domInteractive9121011
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@Gudahtt Gudahtt dismissed stale reviews from danjm and davidmurdoch via 0d94a8a June 20, 2024 16:57
@Gudahtt Gudahtt force-pushed the handle-offscreen-document-already-exists-error branch 2 times, most recently from 6eb8858 to ac73ecc Compare June 20, 2024 16:58
@metamaskbot
Copy link
Collaborator

Builds ready [ac73ecc]
Page Load Metrics (53 ± 5 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint7010885115
domContentLoaded9151121
load417353115
domInteractive8151121
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 228 Bytes (0.01%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@Gudahtt Gudahtt added the needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) label Jun 20, 2024
@Gudahtt Gudahtt force-pushed the handle-offscreen-document-already-exists-error branch from ac73ecc to b54361b Compare June 24, 2024 19:04
// Report unrecongized errors without halting wallet initialization
// Failures to create the offscreen document does not compromise wallet data integrity or
// core functionality, it's just needed for specific features.
captureException(error);
Copy link
Member Author

@Gudahtt Gudahtt Jun 24, 2024

Choose a reason for hiding this comment

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

Just updated this to catch all platform errors here (as suggested by @FrederikBolding on Slack) to avoid bricking the wallet if something else goes wrong here. We're still capturing the error in Sentry, and this is a non-essential step, so this should be a safe way to approach this for now.

See commit ffb2c3a

@metamaskbot
Copy link
Collaborator

Builds ready [ffb2c3a]
Page Load Metrics (49 ± 3 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint70968273
domContentLoaded9151111
load42604953
domInteractive9151111
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 351 Bytes (0.01%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@Gudahtt Gudahtt force-pushed the handle-offscreen-document-already-exists-error branch from ffb2c3a to 429d147 Compare July 15, 2024 12:24
@metamaskbot
Copy link
Collaborator

Builds ready [429d147]
Page Load Metrics (151 ± 170 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint64147972110
domContentLoaded105924168
load401695151355170
domInteractive105924168
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 351 Bytes (0.01%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@Gudahtt Gudahtt force-pushed the handle-offscreen-document-already-exists-error branch 2 times, most recently from 08e0378 to 440e581 Compare July 16, 2024 17:24
A `try..catch` block has been added to catch errors about the Offscreen
document already existing. This circumstance is not a bug, it's
expected to happen sometimes due to race conditions between
`hasDocument` and the creation step. The code in question is just meant
to create the document if it doesn't exist, so it's OK if we get this
error.

The `hasDocument` call has been removed as well, since it's now
redundant. This function wasn't safe to call anyway; it's an
undocumented private function.

See here for more information:
* https://stackoverflow.com/a/7725839
* https://groups.google.com/a/chromium.org/g/chromium-extensions/c/D5Jg2ukyvUc4

Fixes #25118
We now capture unrecognized errors and report them to Sentry, rather
than throwing them. This ensures that any new failures would not brick
the wallet.
@Gudahtt Gudahtt force-pushed the handle-offscreen-document-already-exists-error branch from 440e581 to 8341502 Compare July 18, 2024 13:40
Copy link

sonarcloud bot commented Jul 18, 2024

@metamaskbot
Copy link
Collaborator

Builds ready [8341502]
Page Load Metrics (68 ± 7 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint7212898168
domContentLoaded9512594
load4710068147
domInteractive9512594
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 351 Bytes (0.01%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@Gudahtt Gudahtt merged commit f434c0f into develop Jul 18, 2024
78 of 79 checks passed
@Gudahtt Gudahtt deleted the handle-offscreen-document-already-exists-error branch July 18, 2024 14:23
@github-actions github-actions bot locked and limited conversation to collaborators Jul 18, 2024
@github-actions github-actions bot removed the needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) label Jul 18, 2024
@metamaskbot metamaskbot added the release-12.3.0 Issue or pull request that will be included in release 12.3.0 label Jul 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.3.0 Issue or pull request that will be included in release 12.3.0 team-extension-platform
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Error: Only a single offscreen document may be created.
5 participants