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:
Ivan Enderlin
2022-11-09 14:34:40 +01:00
parent 93be96c85c
commit 3fe63c328f

View File

@@ -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 {