Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
Which function will be called a second time when a firebase transcation fails the first time?

The Firebase documentation claims:

A function calling a transaction (transaction function) might run more than once if a concurrent edit affects a document that the transaction reads.

It is unclear exactly which function will run twice when there is a concurrent edit. In the example below, outerFunc calls the runTranscation method, so a literal interpretation of the documentation would imply that that outerFunc may be called twice.

However, this seems like a strange implementation, and I suspect that the docs mean to say that innerFunc may be called more than once when there is a concurrent edit.

import { runTransaction } from "firebase/firestore";

function outerFunc () {
  console.log('outerFunction');
  try {
    await runTransaction(db, async function innerFunc(transaction) {
      const sfDoc = await transaction.get(sfDocRef);
      if (!sfDoc.exists()) {
        throw "Document does not exist!";
      }

      const newPopulation = sfDoc.data().population + 1;
      transaction.update(sfDocRef, { population: newPopulation });
    });
    console.log("Transaction successfully committed!");
  } catch (e) {
    console.log("Transaction failed: ", e);
  }
}

Could outerFunc be called twice when there is a concurrent edit as the doc imply?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There's no way the Firestore SDK can invoke your outerFunc (let alone multiple times), but your innerFunc callback may be called multiple times by the Firestore SDK indeed.

If you find the documentation confusing, please file feedback on the page itself. There should be a link for that at the bottom right.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!