5.5. Aborting a transaction

The steps to abort a transaction are as follows. This algorithm takes two arguments: the transaction to abort, and error.

  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. If error is not null, set transaction’s error to error.

  4. For each request in transaction’s request list with done flag unset, abort the steps to asynchronously execute a request for request and queue a task to run these steps:

    1. Set the done flag on request.

    2. Set the result of request to undefined.

    3. Set the error of request to a newly created[AbortError](https://www.w3.org/TR/WebIDL-1/#aborterror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

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

  1. This does not always result in any `error` events being fired. For example if a transaction is aborted due to an error while [committing](#transaction-commit) 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, set the database‘s upgrade transaction to null.

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

    3. If transaction is an upgrade transaction, then:

      1. Let request be the request associated with transaction.

      2. Set request’s transaction to null.

      3. Set request’s result to undefined.

      4. Unset request’s done flag.