6
votes

We do a lot of image processing in Google Cloud Functions using NodeJS and Sharp (libvips) library. Even though we have the memory limit for our functions set to 2Gb the function occasionally runs out of memory and crashes with the 'Error: memory limit exceeded. Function invocation was interrupted.' message.

Is there a way to catch this exception? I want to return a more polite (json) response so my server knows what the problem was.

1

1 Answers

2
votes

Application-wide uncaught exceptions in NodeJS Google Cloud Platform apps need to be reported manually.

That being said, more details on the memory limit exceeded error could already be on the logs. You only need to search the error message on the Logs viewer from the GCP console as shown in the docs, or use Advanced Filters e.g. to search by time. The documentation also explains how to write log entries from your Cloud Functions. Then you can use the Stackdriver Logging API, for instance, to export the logs and get a json.

I would also suggest using Stackdriver Monitoring to track the memory usage of your Cloud Function.