Skip to content

Ads-Client: refactor shutdown procedure - #7584

Merged
thesuzerain merged 6 commits into
mainfrom
ads-client-revamp-shutdown
Sep 4, 2026
Merged

Ads-Client: refactor shutdown procedure#7584
thesuzerain merged 6 commits into
mainfrom
ads-client-revamp-shutdown

Conversation

@thesuzerain

@thesuzerain thesuzerain commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

This fixes two issues related to the uniffi crash error:

  • The Builder was holding on to a reference to the telemetry. So if you closed the app too quickly, the JS side would not have collected the Builder and destroyed the secondary telemetry reference.
  • The shutdown function is waiting on a lock on the entire AdsClient. This means that when we fixed the async issue in m-c (that shutdown is behaving fire and forget rather than awaiting for it), it can now hang if timing is unlucky. This refactors the shutdown procedure to only await on the telemetry call to the JS layer (the minimum we can lock on).
    • However, as discussed, this temporarily removes the shutdown of the HttpCache, in favor of future refactors.

Pull Request checklist

  • Breaking changes: This PR follows our breaking change policy
    • This PR follows the breaking change policy:
      • This PR has no breaking API changes, or
      • There are corresponding PRs for our consumer applications that resolve the breaking changes and have been approved
  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGELOG.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due diligence applied in selecting them.

}

#[test]
fn test_shutdown_telemetry_basic() {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

These tests are not identical to the ones before, notice the use of MozAdsClientBuilder instead of an internal function to create an AdsClient. This is because I've moved some of the shutdown logic outside of AdsClient to not have to get a lock on the entire AdsClient. I think the logic of these tests should be functionally identical, but worth noting.

// Log the error, but continue with shutdown.
error!("Failed to shutdown the ads client: {:?}", err);
}
self.shutdown_references.shutdown();

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Note the significant difference here: we are no longer shutting down the sqlite database 'safely', as it doesn't seem to be needed to do to fix this crash. We will revisit this in another refactor.

@thesuzerain
thesuzerain marked this pull request as ready for review September 4, 2026 17:14
@thesuzerain
thesuzerain requested a review from a team as a code owner September 4, 2026 17:14

@jonesetc jonesetc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good!

@thesuzerain
thesuzerain added this pull request to the merge queue Sep 4, 2026
Merged via the queue into main with commit c0877e1 Sep 4, 2026
15 checks passed
@thesuzerain
thesuzerain deleted the ads-client-revamp-shutdown branch September 4, 2026 18:38
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.

3 participants