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 breakage report race condition. #2939

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

sammacbeth
Copy link
Collaborator

@sammacbeth sammacbeth commented Feb 5, 2025

Reviewer:

Description:

Some breakage reports were coming through with config version undefined on Firefox (https://app.asana.com/0/0/1209244730607066/f). This is likely caused by a race condition in the breakage report flow if the background is not fully loaded yet.

To fix this, this PR:

  • Moves the sendBreakageReport function to a component.
  • Removes static access to page context information, using components instead.
  • Allows us to wait for the correct config lifecycle event before getting config version.
  • Updates the toggle reports component to use this new entrypoint for sending reports.

Steps to test this PR:

Automated tests:

  • Unit tests
  • Integration tests
Reviewer Checklist:
  • Ensure the PR solves the problem
  • Review every line of code
  • Ensure the PR does no harm by testing the changes thoroughly
  • Get help if you're uncomfortable with any of the above!
  • Determine if there are any quick wins that improve the implementation
PR Author Checklist:
  • Get advice or leverage existing code
  • Agree on technical approach with reviewer (if the changes are nuanced)
  • Ensure that there is a testing strategy (and documented non-automated tests)
  • Ensure there is a documented monitoring strategy (if necessary)
  • Consider systems implications

Config processing can how take one tick after the config ready promise
resolves. Waiting for allLoadingFinished should ensure that everything is ready.
@sammacbeth sammacbeth requested a review from kzar February 5, 2025 10:56
@@ -321,6 +321,8 @@ export async function breakageReportForTab({
export async function sendBreakageReportForCurrentTab({ pixelName, currentTab, category, description, reportFlow }) {
await settings.ready();
await tdsStorage.ready('config');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason to wait for both tdsStorage.ready('config') and tdsStorage.config.allLoadingFinished?

@sammacbeth sammacbeth force-pushed the sam/breakage-config-version branch from a8bc2fe to 7f4d812 Compare February 6, 2025 12:39
Copy link
Collaborator

@kzar kzar left a comment

Choose a reason for hiding this comment

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

Overall I like the changes, but can we split the race condition fix out from the refactor? Also, I'd like to avoid weakening the ToggleReports unit tests.

1,
2,
);
await expectReports([[{}, 'protection-toggled-off-breakage-report', 'on_protections_off_dashboard_main']], 1, 2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd like to keep the test coverage here for the actual pixels being sent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see your point, but what would that actually test? It would actually just be a test of dashboardMessaging.submitBrokenSiteReport, that it passes the arguments given here correctly to the pixel request. That would be better encapsulated in a separate unit-test.

Part of the advantage of this refactor, is that we can mock the boundaries of ToggleReport better - rather than having to intercept the outgoing pixel to test that a report was sent, we can just mock the interface for sending reports.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note, I've added some new tests for dashboardMessaging.submitBrokenSiteReport explicitly, so I think everything should be now covered. The toggle-reports tests test everything up to the submitBrokenSiteReport call, then the dashboard-messaging tests check that call to pixel sent.

shared/js/background/components/dashboard-messaging.js Outdated Show resolved Hide resolved
*/
async submitBrokenSiteReport(breakageReport, pixelName = 'epbf', reportFlow = undefined) {
// wait for config and TDS so we can get etags and config version
await Promise.all([this.tds.remoteConfig.allLoadingFinished, this.tds.tds.ready]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it just this await Promise.all([this.tds.remoteConfig.allLoadingFinished, this.tds.tds.ready]); that's resolving the race condition, or are there other changes here that do too? I'm thinking we should split this into two PRs, one for the race condition and one for the refactor.

/**
* Message handlers for communication from the dashboard to the extension background.
*
* Note, additional message handles for toggle reports is in the separate ToggleReports component.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there are other dashboard messages that we didn't move here? E.g. for the fire button. Maybe we should mention some of those in the comment here, or move the handlers into this component too? I think the docs here might help https://duckduckgo.github.io/privacy-dashboard/modules/Browser_Extensions_integration.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've updated that docstring to include all messages and where they are being handled. Thanks for pointing to those docs, super helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants