I am analyzing logs that show the error "Too much contention on these documents. Please try again". What is strange here is that logs within the transactions never executed, which seems to indicate the transactions never made a write attempt. In the below example, the error says there was contention at runTransaction though "Updating documents" is not in any of the logs.
If there was no write operation performed on the documents (note these transactions are the only way these documents are updated), how is it possible there was contention? That is, if there were never any writes, given transactions allow reads from outside of the transaction how could the below code lead to contention? Obviously I understand that a few of these transactions on the same documents trying to write would trigger contention, but in this case, "Updating documents" never executed so it isn't possible there was ever a write attempt.
Put more simply: for there to be contention, there needs to be write calls; but for there to be write calls, "Updating documents" needed to trigger; "Updating documents" did not trigger, and therefore there couldn't have been write calls, so there shouldn't have been contention.
return db.runTransaction((transaction) => {
return transaction.get(query).then((querySnapshot) => {
console.log("Updating documents");
[transaction code here to update documents]
}
});