webxdc / store

XDC store, migrated to codeberg
https://codeberg.org/webxdc/store
5 stars 0 forks source link

xdcs downloaded while the store is closed fail to change the state to "downloaded" #203

Closed link2xt closed 1 year ago

link2xt commented 1 year ago

This bug happens on Android. I set the download limit to 40 KiB, sent a message to the store bot, downloaded store.xdc and opened it. Inside the store I downloaded two large .xdcs and closed the store to open the store bot chat. Inside the store bot chat I manually downloaded two received xdcs and then opened the store again.

The store did not show the xdcs as downloaded, the console (bot is built with eruda) shows two messages "Received webxdc" and two uncaught exception errors. The first error is: {"stack":"Error: Failed to execute 'put' on 'IDBObjectStore': Evaluating the object store's key path did not yield a value.\n at https://acc1-msg301763.localhost/assets/index-9e6f0575.js:1:48330\n at new Promise ()\n at Ni.update (https://acc1-msg301763.localhost/assets/index-9e6f0575.js:1:48207)\n at async qi (https://acc1-msg301763.localhost/assets/index-9e6f0575.js:1:50764)"}

See also my comment at the core repo: https://github.com/deltachat/deltachat-core-rust/issues/4543#issuecomment-1648769533

As a starter I think we need more logs around the place where we try to store the webxdc.

Searching the web for Error: Failed to execute 'put' on 'IDBObjectStore': Evaluating the object store's key path did not yield a value. I found this: https://stackoverflow.com/questions/48988590/uncaught-domexception-failed-to-execute-put-on-idbobjectstore-evaluating-t

link2xt commented 1 year ago

Got the same problem on Desktop as well. Downloaded the store, inside the store requested Reactle, closed the store, downloaded the update message, reopened the store, got this: 1

link2xt commented 1 year ago

put is failing here: https://github.com/webxdc/store/blob/af3b40c67eddb0dd213393989ca42f1fffebf6fc/frontend/src/db/store_db.ts#L77

So the frontend successfully stores the base64 blob in apps storage (which uses out-of-line keys and does not have a key path mentioned in the error message), but then fails to set the state of the app in the appInfo storage.

link2xt commented 1 year ago

So the problem is that when the store.xdc is just opened, appInfo store here is not populated yet: https://github.com/webxdc/store/blob/af3b40c67eddb0dd213393989ca42f1fffebf6fc/frontend/src/store-logic.ts#L95C19-L95C19

As a result, appInfo[payload.app_id] is undefined. So I think instead of trying to pass the appInfo used by view into update I will modify the update function to read this from the database in the same transaction. IndexedDB is a transactional database after all.