Bug: RemoteSettingsWorker error: Error: Can't import when we've started shutting down
Status: NEW
Priority: --
Created: 2023-01-02 08:57:00+00:00
Resolved: 2025-01-15 11:07:31+00:00

Several tests in CI that are using Marionette as underlying harness showing the following failure during shutdown which is causing task timeouts due to a lot of restarts of Firefox (bug 1589796): 

https://treeherder.mozilla.org/logviewer?job_id=400022129&repo=try&lineNumber=58642-58660 

```
task 2022-12-18T14:32:32.823Z] 14:32:32     INFO - 1671373952821	Marionette	DEBUG	Marionette stopped listening
[task 2022-12-18T14:32:32.860Z] 14:32:32     INFO - console.error: (new TypeError("NetworkError: Network request failed", "resource://services-settings/Utils.jsm", 230))
[task 2022-12-18T14:32:40.260Z] 14:32:40     INFO - console.error: "Failed to import bookmarks from chrome://browser/content/default-bookmarks.html: Error: places.sqlite#1: cannot execute operation Bookmarks.jsm: insertBookmarkTree, the connection is already closing"
[task 2022-12-18T14:32:42.135Z] 14:32:42     INFO - JavaScript error: resource://gre/modules/AsyncShutdown.jsm, line 718: Error: Phase "IOUtils: waiting for profileBeforeChange IO to complete" is finished, it is too late to register completion condition "JSON store: writing data for 'shieldpreferenceexperiments'"
[task 2022-12-18T14:32:42.875Z] 14:32:42     INFO - WARNING: At least one completion condition is taking too long to complete. Conditions: [{"name":"Places Connection shutdown","state":{"PlacesShutdownProgress":5},"filename":"/builds/worker/checkouts/gecko/toolkit/components/places/Database.cpp","lineNumber":470,"stack":""},{"name":"Remote Settings profile-before-change","state":"Remaining: 5 callbacks (importJSONDump-main-anti-tracking-url-decoration-1, importJSONDump-main-hijack-blocklists-2, importJSONDump-main-doh-providers-3, importJSONDump-main-search-telemetry-v2-4, importJSONDump-main-search-config-5).","filename":"resource://services-settings/RemoteSettingsWorker.jsm","lineNumber":203,"stack":["resource://services-settings/RemoteSettingsWorker.jsm:null:203","resource://services-settings/RemoteSettingsClient.jsm:_importJSONDump:938","resource://services-settings/RemoteSettingsClient.jsm:get/this._importingPromise<:443","resource://services-settings/RemoteSettingsClient.jsm:get:458"]}] Barrier: profile-before-change
[task 2022-12-18T14:32:57.496Z] 14:32:57     INFO - console.log: "RemoteSettingsWorker error: Error: Can't import when we've started shutting down."
[task 2022-12-18T14:32:57.497Z] 14:32:57     INFO - console.error: (new RemoteSettingsWorkerError("Error: Can't import when we've started shutting down.", "resource://services-settings/RemoteSettingsWorker.jsm", 48))
[task 2022-12-18T14:32:58.247Z] 14:32:58     INFO - JavaScript error: resource://activity-stream/lib/PlacesFeed.jsm, line 187: NS_ERROR_UNEXPECTED: Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsINavBookmarksService.addObserver]
[task 2022-12-18T14:32:58.248Z] 14:32:58     INFO - JavaScript error: resource://gre/modules/ExtensionSettingsStore.jsm, line 122: Error: The ExtensionSettingsStore was accessed before the initialize promise resolved.
[task 2022-12-18T14:32:59.933Z] 14:32:59     INFO - console.log: "RemoteSettingsWorker error: Error: Can't import when we've started shutting down."
[task 2022-12-18T14:32:59.934Z] 14:32:59     INFO - console.error: (new RemoteSettingsWorkerError("Error: Can't import when we've started shutting down.", "resource://services-settings/RemoteSettingsWorker.jsm", 48))
[task 2022-12-18T14:32:59.936Z] 14:32:59     INFO - console.log: "RemoteSettingsWorker error: Error: Can't import when we've started shutting down."
[task 2022-12-18T14:32:59.937Z] 14:32:59     INFO - console.log: "RemoteSettingsWorker error: Error: Can't import when we've started shutting down."
[task 2022-12-18T14:32:59.938Z] 14:32:59     INFO - console.error: (new RemoteSettingsWorkerError("Error: Can't import when we've started shutting down.", "resource://services-settings/RemoteSettingsWorker.jsm", 48))
[task 2022-12-18T14:32:59.939Z] 14:32:59     INFO - console.error: (new RemoteSettingsWorkerError("Error: Can't import when we've started shutting down.", "resource://services-settings/RemoteSettingsWorker.jsm", 48))
[task 2022-12-18T14:32:59.939Z] 14:32:59     INFO - console.log: "RemoteSettingsWorker error: Error: Can't import when we've started shutting down."
[task 2022-12-18T14:32:59.940Z] 14:32:59     INFO - console.error: (new Error("IndexedDB: main/doh-config getLastModified() IndexedDB:  execute() The application is shutting down", "resource://services-settings/IDBHelpers.jsm", 18))
[task 2022-12-18T14:32:59.945Z] 14:32:59     INFO - console.error: (new RemoteSettingsWorkerError("Error: Can't import when we've started shutting down.", "resource://services-settings/RemoteSettingsWorker.jsm", 48))
```

This is also adding a good amount of delay for each and every shutdown. But not sure if this is related to `RemoteSettings`. A related bug for the Places entry has been filed as bug 1806358.