Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Degration of indexeddb to MemoryStore does not work anymore #2384

Closed
schmop opened this issue May 19, 2022 · 3 comments · Fixed by #2385
Closed

Degration of indexeddb to MemoryStore does not work anymore #2384

schmop opened this issue May 19, 2022 · 3 comments · Fixed by #2385
Assignees

Comments

@schmop
Copy link
Contributor

schmop commented May 19, 2022

Describe the bug
If the indexeddb throws an exception, normally the store would have degraded on a MemoryStore.
This does not longer work, because of the switch to the async-notation. The exceptions do not get caught and the degration will not be started.

To Reproduce
Steps to reproduce the behavior:

  1. Client startup with custom indexeddb in store
import db from './customindexeddb';

let opts = {
  store: new matrixcs.IndexedDBStore(
    indexeddb: db,
    dbName: 'matrix-store',
  ),
  baseUrl: "https://matrix.org",
};

var client = matrixcs.createClient(opts);
client.store.startup();
  1. customindexeddb is programmed to throw on reading from object stores
  2. MatrixClient crashes, but does not degrade to MemoryStore

Expected behavior
An error is thrown in the console, indexeddb will not be used anymore, and the backend store falls back to the MemoryStore.

@t3chguy
Copy link
Member

t3chguy commented May 19, 2022

Can you share any errors or stack traces maybe?

@schmop
Copy link
Contributor Author

schmop commented May 19, 2022

Not sure if this helps:

Stack trace
logger.js?3eb4:59 IndexedDBStore.startup: connecting to backend
logger.js?3eb4:59 LocalIndexedDBStoreBackend.connect: connecting...
logger.js?3eb4:59 LocalIndexedDBStoreBackend.connect: awaiting connection...
logger.js?3eb4:59 LocalIndexedDBStoreBackend.connect: connected
logger.js?3eb4:59 LocalIndexedDBStoreBackend: loading account data...
logger.js?3eb4:59 LocalIndexedDBStoreBackend: loading sync data...
logger.js?3eb4:59 LocalIndexedDBStoreBackend: loaded account data
logger.js?3eb4:59 LocalIndexedDBStoreBackend: loaded sync data
logger.js?3eb4:59 LocalIndexedDBStoreBackend: loaded initial data
logger.js?3eb4:59 IndexedDBStore.startup: loading presence events
logger.js?3eb4:59 IndexedDBStore.startup: processing presence events
logger.js?3eb4:59 Fetching new TURN credentials
logger.js?3eb4:59 Getting saved sync token...
logger.js?3eb4:59 Getting push rules...
logger.js?3eb4:59 Got saved sync token
logger.js?3eb4:59 Getting saved sync...
logger.js?3eb4:59 Got reply from saved sync, exists? false
logger.js?3eb4:59 Got push rules
logger.js?3eb4:59 Checking lazy load status...
logger.js?3eb4:59 Checking whether lazy loading has changed in store...

indexeddb-local-backend.js?f817:87 Uncaught (in promise) Error: Query failed: Error: Integrity check failed
    at EncryptedRequest.query.onerror (indexeddb-local-backend.js?f817:87:1)
    at DecryptingCursor.get (decrypting-cursor.js?34a9:11:1)
    at eval (indexeddb-local-backend.js?f817:574:1)
    at EncryptedRequest.query.onsuccess (indexeddb-local-backend.js?f817:99:1)
    at IDBRequest._this3.parent.<computed> (cascading-event-target.js?cd68:37:1)
query.onerror @ indexeddb-local-backend.js?f817:87
get @ decrypting-cursor.js?34a9:11
eval @ indexeddb-local-backend.js?f817:574
query.onsuccess @ indexeddb-local-backend.js?f817:99
_this3.parent.<computed> @ cascading-event-target.js?cd68:37
await in _this3.parent.<computed> (async)
getPushRules @ sync.js?4667:540
await in getPushRules (async)
sync @ sync.js?4667:685
startClient @ client.js?62ec:466
await in startClient (async)

_callee$ @ index.js?0606:364
tryCatch @ runtime.js?96cf:63
invoke @ runtime.js?96cf:294
eval @ runtime.js?96cf:119
asyncGeneratorStep @ index.js:83
_next @ index.js:85
Promise.then (async)
asyncGeneratorStep @ index.js:83
_next @ index.js:85
Promise.then (async)
asyncGeneratorStep @ index.js:83
_next @ index.js:85
eval @ index.js:85
eval @ index.js:85
setupClient @ index.js?0606:257
finalizeAuthentication @ index.js?0606:222
retrieveUserInfo @ index.js?0606:244
login @ index.js?0606:197
eval @ index.js?0606:832
./assets/src/backend/index.js @ backend.cab1c6b4.js:18
__webpack_require__ @ standalone.2e25e533.js:9841
Promise.then (async)
_callee2$ @ messenger-view.vue?f34c:271
tryCatch @ runtime.js?96cf:63
invoke @ runtime.js?96cf:294
eval @ runtime.js?96cf:119
asyncGeneratorStep @ index.js??vue-loader-options!./assets/src/components/messenger-view.vue?vue&type=script&lang=js&:64
_next @ index.js??vue-loader-options!./assets/src/components/messenger-view.vue?vue&type=script&lang=js&:66
eval @ index.js??vue-loader-options!./assets/src/components/messenger-view.vue?vue&type=script&lang=js&:66
eval @ index.js??vue-loader-options!./assets/src/components/messenger-view.vue?vue&type=script&lang=js&:66
mounted @ messenger-view.vue?f34c:270
callHook @ vue.esm.js:2920
insert @ vue.esm.js:4153
invokeInsertHook @ vue.esm.js:5948
patch @ vue.esm.js:6167
Vue._update @ vue.esm.js:2659
updateComponent @ vue.esm.js:2787
get @ vue.esm.js:3141
Watcher @ vue.esm.js:3130
mountComponent @ vue.esm.js:2794
Vue.$mount @ vue.esm.js:8528
Vue.$mount @ vue.esm.js:10925
Vue._init @ vue.esm.js:4628
Vue @ vue.esm.js:4717
init @ chat-standalone.js?babe:11
i.init @ iserv.b806a41b.js:2
(anonym) @ iserv.b806a41b.js:2
u @ jquery.c212efcd.js:2
fireWith @ jquery.c212efcd.js:2
ready @ jquery.c212efcd.js:2
R @ jquery.c212efcd.js:2

It references following Code snippets:

// indexeddb-local-backend.js : 87
function selectQuery(store, keyRange, resultMapper) {
  const query = store.openCursor(keyRange);
  return new Promise((resolve, reject) => {
    const results = [];

    query.onerror = () => {
      reject(new Error("Query failed: " + query.error));
    }; // collect results
    // [...]
}

This error is not caught from the degradable-method in indexeddb.ts:

// indexeddb.ts:292
    private degradable<A extends Array<any>, R = void>(
        func: DegradableFn<A, R>,
        fallback?: string,
    ): DegradableFn<A, R> {
        const fallbackFn = super[fallback];

        return async (...args) => {
            try {
                return func.call(this, ...args); // THIS DOES NOT CATCH THE FAILING PROMISE
            } catch (e) {
            [...]            

@t3chguy
Copy link
Member

t3chguy commented May 19, 2022

Yup good spot, has a missing await

schmop pushed a commit to schmop/matrix-js-sdk that referenced this issue May 19, 2022
@t3chguy t3chguy self-assigned this May 19, 2022
t3chguy pushed a commit that referenced this issue May 19, 2022
t3chguy pushed a commit that referenced this issue May 20, 2022
Co-authored-by: Lars Richard <[email protected]>
(cherry picked from commit 81d884f)
t3chguy added a commit that referenced this issue May 20, 2022
Co-authored-by: Lars Richard <[email protected]>
(cherry picked from commit 81d884f)

Co-authored-by: schmop <[email protected]>
su-ex added a commit to SchildiChat/matrix-js-sdk that referenced this issue Jun 7, 2022
* Convert `getLocalAliases` to a stable API call ([\matrix-org#2402](matrix-org#2402)).
* Fix request, crypto, and bs58 imports ([\matrix-org#2414](matrix-org#2414)). Fixes matrix-org#2415.
* Update relations after every decryption attempt ([\matrix-org#2387](matrix-org#2387)). Fixes element-hq/element-web#22258. Contributed by @weeman1337.
* Fix degraded mode for the IDBStore and test it ([\matrix-org#2400](matrix-org#2400)). Fixes matrix-org/element-web-rageshakes#13170.
* Don't cancel SAS verifications if `ready` is received after `start` ([\matrix-org#2250](matrix-org#2250)).
* Prevent overlapping sync accumulator persists ([\matrix-org#2392](matrix-org#2392)). Fixes vector-im/element-web#21541.
* Fix behaviour of isRelation with relation m.replace for state events ([\matrix-org#2389](matrix-org#2389)). Fixes element-hq/element-web#22280.
* Fixes matrix-org#2384 ([\matrix-org#2385](matrix-org#2385)). Fixes undefined/matrix-js-sdk#2384. Contributed by @schmop.
* Ensure rooms are recalculated on re-invites ([\matrix-org#2374](matrix-org#2374)). Fixes element-hq/element-web#22106.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment