Skip to content

Commit 7a98673

Browse files
committed
Close Remote settings DB connections
Made the `RevelancyStore::close` method also close the remote settings client. This way we can close things down on Desktop during shutdown and avoid LateWrite errors that happen when an open SQLite connection is garbage collected.
1 parent b310c3a commit 7a98673

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

components/relevancy/src/ingest.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ mod test {
170170
.unwrap_or_else(|| unreachable!("Unexpected request for attachment `{}`", location))
171171
.clone())
172172
}
173+
174+
fn close(&self) {}
173175
}
174176

175177
#[test]

components/relevancy/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ impl<C: rs::RelevancyRemoteSettingsClient> RelevancyStoreInner<C> {
164164
///
165165
/// Calling `close` will interrupt any in-progress queries on other threads.
166166
pub fn close(&self) {
167-
self.db.close()
167+
self.db.close();
168+
self.client.close();
168169
}
169170

170171
/// Interrupt any current database queries

components/relevancy/src/rs.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ pub(crate) trait RelevancyRemoteSettingsClient {
1919
/// Fetches a record's attachment from the Suggest Remote Settings
2020
/// collection.
2121
fn get_attachment(&self, location: &RemoteSettingsRecord) -> Result<Vec<u8>>;
22+
23+
/// Close any open resources
24+
fn close(&self);
2225
}
2326

2427
impl RelevancyRemoteSettingsClient for RemoteSettingsClient {
@@ -32,6 +35,10 @@ impl RelevancyRemoteSettingsClient for RemoteSettingsClient {
3235
fn get_attachment(&self, record: &RemoteSettingsRecord) -> Result<Vec<u8>> {
3336
Ok(self.get_attachment(record)?)
3437
}
38+
39+
fn close(&self) {
40+
self.shutdown()
41+
}
3542
}
3643

3744
impl<T: RelevancyRemoteSettingsClient> RelevancyRemoteSettingsClient for &T {
@@ -42,6 +49,10 @@ impl<T: RelevancyRemoteSettingsClient> RelevancyRemoteSettingsClient for &T {
4249
fn get_attachment(&self, record: &RemoteSettingsRecord) -> Result<Vec<u8>> {
4350
(*self).get_attachment(record)
4451
}
52+
53+
fn close(&self) {
54+
(*self).close();
55+
}
4556
}
4657

4758
impl<T: RelevancyRemoteSettingsClient> RelevancyRemoteSettingsClient for std::sync::Arc<T> {
@@ -52,6 +63,10 @@ impl<T: RelevancyRemoteSettingsClient> RelevancyRemoteSettingsClient for std::sy
5263
fn get_attachment(&self, record: &RemoteSettingsRecord) -> Result<Vec<u8>> {
5364
(**self).get_attachment(record)
5465
}
66+
67+
fn close(&self) {
68+
(**self).close()
69+
}
5570
}
5671

5772
#[derive(Clone, Debug, Deserialize)]
@@ -121,5 +136,7 @@ pub mod test {
121136
fn get_attachment(&self, _record: &RemoteSettingsRecord) -> Result<Vec<u8>> {
122137
panic!("NullRelavancyRemoteSettingsClient::get_records was called")
123138
}
139+
140+
fn close(&self) {}
124141
}
125142
}

components/remote_settings/src/client.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,7 @@ impl<C: ApiClient> RemoteSettingsClient<C> {
360360
Ok(())
361361
}
362362

363-
/// Close the client
364-
///
365-
/// This is typically used during shutdown. It closes the underlying SQLite connection used to
366-
/// cache records.
367-
pub fn close(&self) {
363+
pub fn shutdown(&self) {
368364
self.inner.lock().storage.close();
369365
}
370366

components/remote_settings/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ impl RemoteSettingsClient {
164164
pub fn sync(&self) -> ApiResult<()> {
165165
self.internal.sync()
166166
}
167+
168+
/// Shutdown the client, releasing the SQLite connection used to cache records.
169+
pub fn shutdown(&self) {
170+
self.internal.shutdown()
171+
}
167172
}
168173

169174
impl RemoteSettingsClient {

0 commit comments

Comments
 (0)