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.
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.
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.
If error is not null, set transaction’s error to error.
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:
Set the done flag on request.
Set the result of request to undefined.
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)
.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.
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.
Queue a task to run these steps:
If transaction is an upgrade transaction, set the database‘s upgrade transaction to null.
Fire an event named
abort
at transaction with its[bubbles](https://www.w3.org/TR/dom41/#dom-event-bubbles)
attribute initialized to true.If transaction is an upgrade transaction, then:
Let request be the request associated with transaction.
Set request’s transaction to null.
Set request’s result to undefined.
Unset request’s done flag.