Retries and transient errors
Which transaction errors are retried and how.
Retry a transaction when it fails with a transient error. The drivers do it for you with withTransaction.
Requirements
- A transaction that already works, such as the one in Multi-document transactions.
The labels
| Label | What to do |
|---|---|
TransientTransactionError | Retry the whole transaction from the start. |
UnknownTransactionCommitResult | Retry only commitTransaction; you do not know if it committed. |
With withTransaction
withTransaction retries what it must according to those labels. If you write the loop yourself, look at the label of
the error and not at the code.
Check
With two clients writing the same document at once, both end up committing thanks to the retries.
Common problems
- A statement that finds a version inside its uncertainty window fails with
WriteConflict; it is solved the same way, by retrying.