Search code examples
firebasegoogle-cloud-firestoregoogle-cloud-functionsfirebase-tools

Firebase Functions: onDocumentCreated retry not firing in the emulator


I've setup a triggered function in Firebase using the onDocumentCreated trigger and noticed there is an option to set a boolean for retry. It is my assumption that this would result in a retry if the function throws an error. So I've setup the following test function and am running it with the local emulator. Unfortunately I have not been able to get the function to be called multiple times even though I see the error in the logs.

Is there another setting anywhere that I might be missing?

export const testRetries = onDocumentCreated(
  {
    document: "/testing/{test}",
    retry: true,
  },
  async (event) => {
    console.log("testRetries");

    throw new Error("test error");
  }
);

I tried running the above code in the emulator and am only seeing it triggered once and then never again.


Solution

  • The Firebase emulator doesn't exactly reproduce the behavior of production, and does not support retries like the Cloud Functions service that it emulates. The fact that the emulator doesn't support retries is mentioned in the documentation:

    The Cloud Functions emulator does not support retrying functions on failure.

    If you want to observe the retry behavior, you should deploy the function and invoke it as it would in a production-like environment.