-
Notifications
You must be signed in to change notification settings - Fork 274
[AC-152] Fixes moz ads telemetry UniFFI callback leak #7520
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
Changes from all commits
988e98b
15744b8
14122ff
066df13
d74aaf8
4b7e8f4
4c1336e
7bc38b4
c2c94f8
226db5f
b26e6fb
684077b
d62ce73
e7b4edb
1543f68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,9 +12,9 @@ use parking_lot::Mutex; | |
| use url::Url as AdsClientUrl; | ||
|
|
||
| use client::AdsClient; | ||
| use error_support::error; | ||
| use http_cache::CachePolicy; | ||
| use mars::ad_request::{AdPlacementRequest, AdRequestFlags}; | ||
|
|
||
| mod client; | ||
| mod ffi; | ||
| pub mod http_cache; | ||
|
|
@@ -52,6 +52,18 @@ impl MozAdsClient { | |
| }) | ||
| } | ||
|
|
||
| // Allows the ads-client to unload some references and prepare for a safe shutdown. | ||
| // Other methods should not be called after this one. | ||
| #[uniffi::method()] | ||
| pub fn shutdown(&self) -> AdsClientApiResult<()> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens in term of idempotency if you were to call that method twice? Would the second one fail?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As it stands, its fine if it runs twice. But I think until we are sure that we want things to work after the call (eg: with regards to future things we need to offload), we should not make that promise yet |
||
| let mut inner = self.inner.lock(); | ||
| if let Err(err) = inner.shutdown_client() { | ||
| // Log the error, but continue with shutdown. | ||
| error!("Failed to shutdown the ads client: {:?}", err); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[handle_error(ComponentError)] | ||
| #[uniffi::method(default(options = None))] | ||
| pub fn record_click( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,13 @@ impl<T: Telemetry> MARSTransport<T> { | |
| } | ||
| } | ||
|
|
||
| pub fn shutdown_db(&mut self) -> Result<(), rusqlite::Error> { | ||
| if let Some(cache) = self.http_cache.take() { | ||
| cache.shutdown_db()?; | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
|
Comment on lines
+32
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this feels similar to https://doc.rust-lang.org/std/ops/trait.Drop.html
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was matching an existing a-s pattern for shutdowns of sqlite here (w.r.t recursive I've no objection to turning this into a trait so happy to do so.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or at least we might need an exposed FFI drop / shutdown function |
||
| pub fn clear_cache(&self) -> Result<(), rusqlite::Error> { | ||
| if let Some(cache) = &self.http_cache { | ||
| cache.clear()?; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.