2
votes

I have a Google Cloud Function subscribed to a topic. Our Go API publishes a message to the topic when an email needs to be sent to a user. The GCF creates the email object and sends it to Sendgrid. The problem is that 90% of the time, the cloud functions gets invoked twice.

The acknowledgement deadline on the subscription is 600 seconds and it's clearly stated in the Docs that GCF acknowledges internally.

I understand that PubSub guarantees at-least-once delivery and GCF at-least-once execution for background functions. But still, this happens in most cases, I'm pretty sure that's not right either.

I'm 100% sure it's not our API that's sending 2 messages. The cloud function runs twice even when I manually publish a message from the GCP console to test.

This is the GCF log:

So the execution_id is the same. Both executions take less than 1 second.

So I'm not sure what's going on, who is responsible for this duplication?

I'm guessing it's GCF seeing as both executions have the same ID?

Does anyone have any ideas about how to fix this?

1
This answer might explain what's going on, but I don't really know how to apply this solution to my Pub/Sub setup.Horea

1 Answers

1
votes

I met almost the same situation. I fixed it by deleting Cloud Functions' entries and Cloud Pub/Sub's subscriptions, then recreating them. It seems work fine so far.