firebase-functions icon indicating copy to clipboard operation
firebase-functions copied to clipboard

Firebase function logging duplicate errors on failure

Open TraGicCode opened this issue 3 years ago • 3 comments

Could anyone help me understand if this is a bug or expected? When i try to fail a firestore trigger function i see the same error show up 2 times with different timestamps.

Cloud Logging image

Code

exports.func = functions
  .firestore
  .document('stuffs/{stuffid}')
  .onWrite((snap, context) => {
    return Promise.reject(new Error("I'm just returning a rejected promise"));
  });

My End goal is:

  1. Log to error log using functions.logger.error
  2. Report error to error reporting
  3. Force a retry of the function since an error occured that is most likely temporal in nature

TraGicCode avatar Jul 26 '22 01:07 TraGicCode

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar Jul 26 '22 01:07 google-oss-bot

@TraGicCode Thanks for raising the issue!

I'm going to poke at some internal folks to see if I can get an answer to the duplicate log issue.

On the other hand, I think there are some complication in Google Cloud Function not handling promise rejections very well. This will certainly lead to container shutdown and thus introduce more cold starts to your service. I suggest handling errors on client side as much as possible - you may also see the duplicate error disappear w/ those changes.

taeold avatar Aug 01 '22 22:08 taeold

Hey @taeold ,

For the comment on retries, When an error occurs I want a retry to occur. This is because there could be a bug or some transient outage.

if there is a transient outage the retry will eventually succeed and no manual intervention will be required.

If there is a bug, I want the retries to continue and an alert to fire. This will allow a developer to resolve the issue and deploy a fix.

If I stop the retries ( by catching and swallowing the error? ) then the event is loss and now I have something that needs to happen that never happened which is not ideal.

in regards to the duplicate log issue, could this be related to the fire base functions framework doing something that is doing this?

TraGicCode avatar Aug 06 '22 12:08 TraGicCode