Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Allow IndexedDB cleanup operations to fail #9903

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/Lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Copyright 2015, 2016 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Copyright 2018 New Vector Ltd
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
Copyright 2019 - 2023 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -926,7 +926,13 @@ async function clearStorage(opts?: { deleteEverything?: boolean }): Promise<void
});

await EventIndexPeg.deleteEventIndex();
await cli.clearStores();
try {
await cli.clearStores();
} catch (_) {
// Clearing the stores failed, which is probably okay, they were
// supposed to be cleared anyway. Any relevant errors were already
// logged.
}
}

/**
Expand Down
44 changes: 44 additions & 0 deletions test/Lifecycle-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2023 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import * as Lifecycle from "../src/Lifecycle";
import { mockPlatformPeg } from "./test-utils";

/**
* Create a fake IndexedDB that mimics Firefox's 'disabled' implementation.
*/
function brokenIDB(): IDBFactory {
return {
deleteDatabase: () => {
// Return an IDBOpenDBRequest that immediately errors
const resp = { onerror: undefined } as IDBOpenDBRequest;
setTimeout(() => resp.onerror?.(new ErrorEvent("")), 1);
return resp;
},
} as unknown as IDBFactory;
}

describe("Lifecycle", () => {
describe("onLoggedOut", () => {
beforeAll(() => mockPlatformPeg());

it("allows IndexedDB failures", async () => {
// Ensure that the indexedDB error is not propagated.
globalThis.indexedDB = brokenIDB();
await Lifecycle.onLoggedOut();
});
});
});