From 4c65587469185af8ac7d0a549c7a29813e6b00ed Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Thu, 28 Mar 2019 12:27:33 +0000 Subject: [PATCH 1/2] Check the local storage fallback for crypto store This adds additional consistency checks to examine the local storage fallback for the crypto store as well as the primary IndexedDB variant. Part of https://github.com/vector-im/riot-web/issues/9309 --- src/utils/StorageManager.js | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/utils/StorageManager.js b/src/utils/StorageManager.js index 472e1c93d4..a669ed9176 100644 --- a/src/utils/StorageManager.js +++ b/src/utils/StorageManager.js @@ -15,6 +15,7 @@ limitations under the License. */ import Matrix from 'matrix-js-sdk'; +import LocalStorageCryptoStore from 'matrix-js-sdk/lib/crypto/store/localStorage-crypto-store'; import Analytics from '../Analytics'; const localStorage = window.localStorage; @@ -78,15 +79,10 @@ export async function checkConsistency() { } if (indexedDB) { - try { - dataInCryptoStore = await Matrix.IndexedDBCryptoStore.exists( - indexedDB, CRYPTO_STORE_NAME, - ); - log(`Crypto store contains data? ${dataInCryptoStore}`); - } catch (e) { + const results = await checkCryptoStore(); + dataInCryptoStore = results.exists; + if (!results.healthy) { healthy = false; - error("Crypto store inaccessible", e); - track("Crypto store inaccessible"); } } else { healthy = false; @@ -111,3 +107,26 @@ export async function checkConsistency() { track("Consistency checks failed"); } } + +async function checkCryptoStore() { + let exists = false; + try { + exists = await Matrix.IndexedDBCryptoStore.exists( + indexedDB, CRYPTO_STORE_NAME, + ); + log(`Crypto store using IndexedDB contains data? ${exists}`); + return { exists, healthy: true }; + } catch (e) { + error("Crypto store using IndexedDB inaccessible", e); + track("Crypto store using IndexedDB inaccessible"); + } + try { + exists = await LocalStorageCryptoStore.exists(localStorage); + log(`Crypto store using local storage contains data? ${exists}`); + return { exists, healthy: true }; + } catch (e) { + error("Crypto store using local storage inaccessible", e); + track("Crypto store using local storage inaccessible"); + } + return { exists, healthy: false }; +} From 83931a4a4238239ce6e9ec40fd0c1027f65cdcf1 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Thu, 28 Mar 2019 12:40:38 +0000 Subject: [PATCH 2/2] Clarify when memory stores are being used This adds logging for the cases where memory only stores are being used. It also reorganises the sync store path to match the crypto store. Part of https://github.com/vector-im/riot-web/issues/9309 --- src/utils/StorageManager.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/utils/StorageManager.js b/src/utils/StorageManager.js index a669ed9176..89fa0d290b 100644 --- a/src/utils/StorageManager.js +++ b/src/utils/StorageManager.js @@ -62,15 +62,9 @@ export async function checkConsistency() { } if (indexedDB && localStorage) { - try { - const dataInSyncStore = await Matrix.IndexedDBStore.exists( - indexedDB, SYNC_STORE_NAME, - ); - log(`Sync store contains data? ${dataInSyncStore}`); - } catch (e) { + const results = await checkSyncStore(); + if (!results.healthy) { healthy = false; - error("Sync store inaccessible", e); - track("Sync store inaccessible"); } } else { healthy = false; @@ -108,6 +102,22 @@ export async function checkConsistency() { } } +async function checkSyncStore() { + let exists = false; + try { + exists = await Matrix.IndexedDBStore.exists( + indexedDB, SYNC_STORE_NAME, + ); + log(`Sync store using IndexedDB contains data? ${exists}`); + return { exists, healthy: true }; + } catch (e) { + error("Sync store using IndexedDB inaccessible", e); + track("Sync store using IndexedDB inaccessible"); + } + log("Sync store using memory only"); + return { exists, healthy: false }; +} + async function checkCryptoStore() { let exists = false; try { @@ -128,5 +138,6 @@ async function checkCryptoStore() { error("Crypto store using local storage inaccessible", e); track("Crypto store using local storage inaccessible"); } + log("Crypto store using memory only"); return { exists, healthy: false }; }