Skip to content

Clarify that deleteDatabase() blocks until open connections close - #44350

Open
vamshikrishnaramasamy wants to merge 3 commits into
mdn:mainfrom
vamshikrishnaramasamy:docs/issue-20368-deletedatabase-blocked
Open

Clarify that deleteDatabase() blocks until open connections close#44350
vamshikrishnaramasamy wants to merge 3 commits into
mdn:mainfrom
vamshikrishnaramasamy:docs/issue-20368-deletedatabase-blocked

Conversation

@vamshikrishnaramasamy

Copy link
Copy Markdown
Contributor

Fixes #20368.

The page mentions that open connections receive a versionchange event, but doesn't explain the consequence: the deletion will not complete (and success will not fire) while any connection to the database is still open. This is a common source of confusion — people wait for onsuccess that never comes because a connection is left open.

This expands the existing sentence to spell out that:

  • the deletion stays pending until every connection closes;
  • a blocked event is fired on the request if a connection doesn't close in response to versionchange;
  • closing connections (e.g. via IDBDatabase.close()) lets the deletion proceed.

This matches the spec's database-deletion steps and the behavior @evanstade quoted on the issue.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vamshikrishnaramasamy
vamshikrishnaramasamy requested a review from a team as a code owner June 4, 2026 01:23
@vamshikrishnaramasamy
vamshikrishnaramasamy requested review from chrisdavidmills and removed request for a team June 4, 2026 01:23
@github-actions github-actions Bot added Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed labels Jun 4, 2026
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Preview URLs (1 page)

(comment last updated: 2026-06-22 20:58:54)

@chrisdavidmills chrisdavidmills left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vamshikrishnaramasamy some comments for you.


When `deleteDatabase()` is called, any other open connections to this
particular database will get a [versionchange](/en-US/docs/Web/API/IDBDatabase/versionchange_event) event.
The deletion does not complete while other connections to the database are still open.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would delete this sentence, as it is placed strangely and repeats what is said in the note.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed it — agreed it was redundant with the note.

giving them the opportunity to close so that the deletion can proceed.

> [!NOTE]
> If a connection is not closed in response to the `versionchange` event, the deletion is

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take this all out of the note block — it works better as regular text, as all of this addition is part of a single flow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulled it out of the note block; it flows better as plain prose now.

> blocked: the request's `success` event does not fire, and a
> [`blocked`](/en-US/docs/Web/API/IDBOpenDBRequest/blocked_event) event is fired on the
> request instead. The deletion stays pending until every connection to the database is
> closed. To let it complete, close each connection — for example by calling

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put "To let it complete..." as a separate paragraph. I'd also edit it to something like

To let it complete, close each connection. This is typically done by calling {{domxref("IDBDatabase.close()")}} from inside the versionchange event handler.

This works better, as you already mentioned versionchange previously.

Maybe also add a short code snippet to show what that typically looks like, and/or link to an example?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworded to your version and split it into its own paragraph. I also added a small snippet showing the versionchange handler closing the connection, matching the style on the versionchange_event page.

@chrisdavidmills chrisdavidmills left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vamshikrishnaramasamy thanks! Just one more comment for you.


```js
// db is an open connection (e.g. from a previous indexedDB.open() success)
db.onversionchange = () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only remaining comment is that I would rewrite this using addEventListener(). That's the more modern practice, and what we usually do in MDN examples.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the snippet to use addEventListener("versionchange", ...) instead. Thanks for the pointer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

indexedDB.deleteDatabase doc: Mention that deleting a database isn't completed until the upgradeNeeded result is closed

3 participants