Saturday, 1 January 2022

Firestore Transaction contention without write attempts?

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.

return db.runTransaction((transaction) => {
   return transaction.get(query).then((querySnapshot) => {
      console.log("Updating documents");
      [transaction code here to update documents]
   }
});


from Firestore Transaction contention without write attempts?

No comments:

Post a Comment