Skip to content

Should IDBDatabase::close() be in parallel? #474

Open

Description

@stelar7

The MDN page says that it happens in a separate thread.
The only other user of this API is IDBFactory::open, where its run in parallel.

Is MDN correct in this case? or should it be synchronous as in the spec?

Activity

  1. SteveBeckerMSFT commented on Sep 22, 2025

    @SteveBeckerMSFT
    Collaborator

    The existing spec looks like it matches Chromium's implementation. Since IDBDatabase::transaction() is also synchronous, we need to set the connection's close pending flag synchronously since it is also checked by transaction().

    Maybe we could improve step 3 when the forced flag is set to false?

    1. Wait for all transactions created using connection to complete. Once they are complete, connection is closed.

    This is not a synchronous wait, but the close may happen in the same thread. Maybe there's a better way to express this?

  2. asutherland commented on Sep 22, 2025

    @asutherland
    Collaborator

    It does seem like most of the algorithms currently expect to be run "in parallel" and https://w3c.github.io/IndexedDB/#close-a-database-connection explicitly is mixing things that must be done synchronously on the agent thread with things that must happen in parallel (but sequentially for the db/all its connections) so it could make sense to:

    Change close()'s algorithm to be:

    1. If connection's close pending flag is set, return.
    2. Set connection’s close pending flag to true.
    3. Run these steps in parallel.
      1. Run close a database connection with this connection.

    We'd then update https://w3c.github.io/IndexedDB/#close-a-database-connection to also handle the need to queue a task since you can't dispatch an event from the "in parallel" conceptual thread, so that text would become:

    1. If the forced flag is true, then for each transaction created using connection run abort a transaction with transaction and newly created "AbortError" DOMException.
    2. Wait for all transactions created using connection to complete. Once they are complete, connection is closed.
    3. If the forced flag is true, then queue a database task to fire an event named close at connection.

    And I think that's compatible with the existing https://w3c.github.io/IndexedDB/#close-a-database-connection use of https://w3c.github.io/IndexedDB/#close-a-database-connection.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      Sponsor
      SponsoredKunjungi sekarang
      Promo