5.5. Aborting a transaction

To abort a transaction with the transaction to abort, and error, run these steps:

  1. All the changes made to the database by the transaction are reverted. For upgrade transactions this includes changes to the set of object stores and indexes, as well as the change to the version. Any object stores and indexes which were created during the transaction are now considered deleted for the purposes of other algorithms.

  2. If transaction is an upgrade transaction, run the steps to abort an upgrade transaction with transaction.

    This reverts changes to all connection, object store handle, and index handle instances associated with transaction.

  3. Set transaction’s state to finished.

  4. If error is not null, set transaction’s error to error.

  5. For each request of transaction’s request list, abort the steps to asynchronously execute a request for request, set request’s processed flag to true, and queue a task to run these steps:

    1. Set request’s done flag to true.

    2. Set request’s result to undefined.

    3. Set request’s error to a newly created[AbortError](https://heycam.github.io/webidl/#aborterror)[DOMException](https://heycam.github.io/webidl/#idl-DOMException).

    4. Fire an event named error at request with its [bubbles](https://dom.spec.whatwg.org/#dom-event-bubbles) and [cancelable](https://dom.spec.whatwg.org/#dom-event-cancelable) attributes initialized to true.

  1. This does not always result in any [`error`](#eventdef-request-error) events being fired. For example if a transaction is aborted due to an error while [committing](#transaction-committing) the transaction, or if it was the last remaining request that failed.
  1. Queue a task to run these steps:

    1. If transaction is an upgrade transaction, then set transaction’s connection‘s associated database‘s upgrade transaction to null.

    2. Fire an event named abort at transaction with its [bubbles](https://dom.spec.whatwg.org/#dom-event-bubbles) attribute initialized to true.

    3. If transaction is an upgrade transaction, then:

      1. Let request be the open request associated with transaction.

      2. Set request’s transaction to null.

      3. Set request’s result to undefined.

      4. Set request’s processed flag to false.

      5. Set request’s done flag to false.