Skip to content

IndexDB: handle missing object store more gracefully #134792

@bpasero

Description

@bpasero

While fixing my storage service in web that is using IndexedDB I noticed that the user data provider leveraging IndexDB is checking whether the object store exists or not:

if (!db.objectStoreNames.contains(store)) {
console.error(`Error while creating indexedDB. Could not create ${store} object store`);
c(null);
return;
}

I wonder if you should adopt a similar strategy that I do by recreating the IndexDB and store so that the user is not ending up with an in-memory solution forever.

Here is my fix: 6c302fb

// It is still possible though that the object store
// we expect is not there (seen in Safari). As such,
// we validate the store is there and otherwise attempt
// once to re-create.
if (!db.objectStoreNames.contains(IndexedDBStorageDatabase.STORAGE_OBJECT_STORE)) {
this.logService.error(`[IndexedDB Storage ${this.name}] onsuccess(): ${IndexedDBStorageDatabase.STORAGE_OBJECT_STORE} does not exist.`);
if (retryOnError) {
this.logService.info(`[IndexedDB Storage ${this.name}] onsuccess(): Attempting to recreate the DB once.`);
// Close any opened connections
db.close();
// Try to delete the db
const deleteRequest = window.indexedDB.deleteDatabase(this.name);
deleteRequest.onsuccess = () => this.doConnect(false /* do not retry anymore from here */).then(resolve, reject);
deleteRequest.onerror = () => {
this.logService.error(`[IndexedDB Storage ${this.name}] deleteDatabase(): ${deleteRequest.error}`);
reject(deleteRequest.error);
};
return;
}
}

Metadata

Metadata

Labels

debtCode quality issuesfile-ioFile I/Oinsiders-releasedPatch has been released in VS Code InsidersverifiedVerification succeededwebIssues related to running VSCode in the web

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions