Why my pub sub message acknowledged? -> Data loss

Viewed 170

I have a cloud function which is called Pub/Sub. It should ACK the message only when it has been correctly processed.

I see in my logs a memory failure, then a message 'Finished with status: ok'. Google Cloud Logs

And the message is acknowledged and removed from my Pub / Sub topic!

Reproducer:

import base64
import requests

def hello_pubsub(event, context):
    """ Triggered from a message on a Cloud Pub/Sub topic.
        Args:
         event (dict): Event payload.
         context (google.cloud.functions.Context): Metadata for the event.
    """
    pubsub_message = base64.b64decode(event['data']).decode('utf-8')
    # let's say that important stuff is done at the line below 
    # which should be retried in case of failure
    r = requests.get('https://zoom.us/client/latest/zoomusInstallerFull.pkg')
    print(pubsub_message)
1 Answers

If the Google Cloud Function is going to be executed, it follows that the subject has already received the ack message.

The messages will receive an ACK if your function successfully completes by returning a resolved promise. PubSub will retry the message if the function throws an error or returns a denied promise.

Therefore, to prevent looping, you must build a retry method that will try a predetermined number of times and then quit. This is necessary if your Cloud Function was unable to process the received message.

Now, in accordance with the previous comment, try allowing retry on failure when an executionID is connected to the request that resulted in error. When a retriable exception is raised, this enables function execution to be retried.

Reviewing for the exact error message that is showing in Cloud Functions which is “Function invocation was interrupted. Error: function terminated”, tt would be advised to check the logs for termination-related information.

Here is further troubleshooting information from the Logging section. Setting up logs to aid in problem-solving can lead to more issues.

Related