Error: Execution Time Limit Exceeded using google-cloud/pubsub

My function executes in 250 milliseconds locally but times out at 92 seconds in the Cloud.

Here’s my code:

exports = async function handler(changeEvent) {
  try {
    const serviceAccount = JSON.parse(context.values.get("serviceAccountSecret"));
    const { PubSub } = require("@google-cloud/pubsub");
    const pubsub = new PubSub({ projectId: serviceAccount.project_id, credentials: serviceAccount });
    const messageData = JSON.stringify(changeEvent);
    const dataBuffer = Buffer.from(messageData);
    console.log("Before pubsub")
    await pubsub.topic("slides-change-stream-events").publish(dataBuffer);
    console.log("After pubsub")
  } catch (e) {
    console.log(e);
  }
}

I’ve tested it with all sorts of logging. It will log “Before pubsub” but then hang on the await call to publish a message. Works great locally. No error is thrown in the logs so I am unable to debug it.

Error Output:
> ran on Mon May 24 2021 09:01:24 GMT-0700 (Pacific Daylight Time)
> took 1m30.011253723s
> error:
execution time limit exceeded
> logs:
Before pubsub

Hey,

Just a random idea, but maybe you had to put your local IP address on a an IP access list so the Google Cloud service knows it needs to expect messages from this particular IP address and did add Realm’s IP address into the same list?

Also, I guess you were able to import google-cloud/pubsub into the Realm dependencies?

Not sure this will help but… At least I tried :smiley: !

Cheers,
Max.

@MaBeuLux88 Thanks for your reply, and I appreciate your trying! :smiley: . The IP address is not an issue and I was able to import the dependencies. I’m also working with Mongo Support.

Here is the current update from support:

I also found some errors on our server side indicating an issue with finding modules which could explain why it’s taking so long.

After doing some further research, it appears that the @google-cloud/pubsub package does not appear to be supported by Realm along with some other GCP packages such as:

  • @google-cloud/debug-agent
  • @google-cloud/logging
  • @google-cloud/logging-bunyan
  • @google-cloud/logging-winston
  • @google-cloud/profiler
  • @google-cloud/trace-agent
  • @google-cloud/connect-datastore

:confused: The rep will be trying to see if there is a way to alleviate the issue.

Currently it seems the MongoDB Functions offering is just way too primitive. For example, I need to write the changes to both pubsub and sqs but installing both npm packages takes the compressed limit of node_modules over 10mb. So I’m limited to very small amount of node_modules which is not realistic.

Thanks,
Govind

I also assumed it was a dependency issue.

You can read more about it here:

This is still a beta feature for this reason. It’s clearly not finished and not working as it should at the moment for many libs… I also suffer for the same problem on a few of my projects :confused:. Hopefully this will be resolved soon!

Let me know if your rep or support contact has a better alternative but I have big doubts for now…

In one of my project I needed slackify-markdown so the only “smart” way I found to get away with this was this:

I created a little REST service that I hosted in a corner of an S3 server that I have that answers to my Realm post queries and answers the result I wanted to execute in my Realm function in the first place…

Silly but… Once the dependencies are fixed and not beta anymore, it will be easy to fix my project and replace the call by the actually module function.

Cheers,
Maxime.

Hi Govind,

As per our discussion in the support ticket, the aforementioned dependencies are currently not supported but we are working to provide this in the near future.

I am keeping track of this work and will circle back around to this thread and update if there is a change to these packages being supported.

Regards
Manny

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.