Skip to content

Commit 4260b2b

Browse files
author
Beatriz Rizental
authored
Merge pull request #1016 from brizental/1742450-no-op-shutdown
Bug 1742450 - Make shutdown a no-op in case Glean is not initialized
2 parents f857177 + 2b918fc commit 4260b2b

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [#988](https://github.com/mozilla/glean.js/pull/988): BUGFIX: Enforce rate limitation at upload time, not at ping submission time.
77
* Note: This change required a big refactoring of the internal uploading logic.
88
* [#1015](https://github.com/mozilla/glean.js/pull/1015): BUGFIX: Make attempting to call the `setUploadEnabled` API before initializing Glean a no-op.
9+
* [#1016](https://github.com/mozilla/glean.js/pull/1016): BUGFIX: Make shutdown a no-op in case Glean is not initialized.
910

1011
# v0.27.0 (2021-11-22)
1112

glean/src/core/glean.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ class Glean {
448448
* Finishes executing all pending tasks
449449
* and shuts down both Glean's dispatcher and the ping uploader.
450450
*
451+
* If Glean is not initialized this is a no-op.
452+
*
451453
* # Important
452454
*
453455
* This is irreversible.
@@ -456,6 +458,11 @@ class Glean {
456458
* @returns A promise which resolves once the shutdown is complete.
457459
*/
458460
static async shutdown(): Promise<void> {
461+
if (!Context.initialized) {
462+
log(LOG_TAG, "Attempted to shutdown Glean, but Glean is not initialized. Ignoring.");
463+
return;
464+
}
465+
459466
// Order here matters!
460467
//
461468
// The dispatcher needs to be shutdown first,

glean/tests/unit/core/glean.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,14 @@ describe("Glean", function() {
553553
assert.ok(postSpy.getCall(0).args[0].indexOf(DELETION_REQUEST_PING_NAME) !== -1);
554554
});
555555

556+
it("attempting to shutdown Glean prior to initialize is a no-op", async function() {
557+
await Glean.testUninitialize();
558+
559+
const launchSpy = sandbox.spy(Context.dispatcher, "launch");
560+
await Glean.shutdown();
561+
assert.strictEqual(launchSpy.callCount, 0);
562+
});
563+
556564
it("events database is initialized at a time when metrics can already be recorded", async function() {
557565
const event = new EventMetricType({
558566
category: "test",

0 commit comments

Comments
 (0)