mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-18 13:40:55 -04:00
fix(indexeddb): Call IDBDatabase.close manually.
Surprisingly, `indexed_db_futures::IdbDatabase` is not closed when dropped.
Hopefully, there is a [`IdbDatabase::close(&self)`][close] method, which calls
`web_sys::IdbDatabase.close`, aka [`IDBDatabase.close`][websys-close], so let's
use it!
`IDBDatabase.close` returns immediately and closes the connection in a separate
thread. The connection isn't actually closed until all transactions created
using this connection are complete. No new transactions can be created for this
connection once this method is called. Methods that create transactions throw
an exception if a closing operation is pending.
[close]: 8c106eb418/src/idb_database.rs (L73-L77)
[websys-close]: https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/close
This commit is contained in:
@@ -283,6 +283,10 @@ impl IndexeddbCryptoStore {
|
||||
}
|
||||
};
|
||||
|
||||
// Must release the database access manually as it's not done when
|
||||
// dropping it.
|
||||
db.close();
|
||||
|
||||
IndexeddbCryptoStore::open_with_store_cipher(prefix, Some(store_cipher.into())).await
|
||||
}
|
||||
|
||||
@@ -943,6 +947,14 @@ impl IndexeddbCryptoStore {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for IndexeddbCryptoStore {
|
||||
fn drop(&mut self) {
|
||||
// Must release the database access manually as it's not done when
|
||||
// dropping it.
|
||||
self.inner.close();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[async_trait(?Send)]
|
||||
impl CryptoStore for IndexeddbCryptoStore {
|
||||
|
||||
Reference in New Issue
Block a user