Skip to content

Retry transactions if possible

Luke Benstead requested to merge retry-transactions-if-possible into master

Firestore transactions (at least locally) timeout after 2 seconds. This is a problem because Firestore operates pessimistic concurrency when using a server client API (e.g. Python) and so locks each entity involved in a transaction and blocks concurrent accesses to that entity. This means another transaction might be forced to wait a while.

The @transactional decorator in Firestore uses a retry system which re-runs the entire decorated function. We can't do that because we only run code during Django's begin/commit functions - we can't retry the whole atomic block. The only time we can retry is if we are the ones controlling the atomic block.

This change retries inserts, updates, and deletes as long as the caller hasn't already started a wider atomic block.

Merge request reports