Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud Function finished with status: 'connection error'

I've got an HTTP Cloud Function (Python 3.7) invoked by a Github webhook, and it usually (but not always) exits with a connection error when the event type is not a pull request. It always exits cleanly when it doesn't go inside the if block.

Here's the function:

def my_func(request):
    event = request.headers.get("X-GitHub-Event", "unknown")
    if event != "pull_request":
        print("This is not a pull request")
        return "This is not a pull request", 200
    return "OK", 200

In the logs it shows up as:

"This is not a pull request"
"Function execution took 11 ms, finished with status: 'connection error'" 

And on the Github side the response is an HTTP/500 error with the message "Error: could not handle the request".

I've redeployed it as a new function in a different project and the same thing happens. Sometimes one function will return 200 and the other returns 500 for the same event. Any idea what's happening here? Thanks :)

like image 886
a_mazz Avatar asked Jan 24 '20 16:01

a_mazz


People also ask

Why Cloud function deployment failed?

Cloud Functions deployment can fail if the entry point to your code, that is, the exported function name, is not specified correctly. Your source code must contain an entry point function that has been correctly specified in your deployment, either via Cloud console or Cloud SDK.

Are Google cloud functions always running?

By essence Cloud Functions are implementing a serverless architecture: they don't run all the time (i.e. permanently), but when they are triggered.


1 Answers

It seems like you are hitting the limits of Max uncompressed HTTP request size in Cloud functions which is 10MB. This might be the reason why some requests are okay and some are not.

You might want to consider using Google App Engine or somehow limiting the size of the request/response from Github.

UPDATE:

The only other thing that is worth testing is trying to set if else conditions for a couple of request types to eliminate the possibility of something going wrong there.

For example:

def my_func(request):
    event = request.headers.get("X-GitHub-Event", "unknown")
    if event == "[Type1]":
        print("This is [Type1]")
        return "This is not a pull request", 200
    elif event == "[Type2]":
        print("This is [Type2]")
    return "OK", 200

It would be interesting to see if the exact same code will work by using GAE instead of Cloud Functions

Otherwise this will be a specific issue with the webhook and needs to be reported on the Github repo of the Github webhook handler or where it's best fit.

like image 188
Waelmas Avatar answered Nov 15 '22 15:11

Waelmas