7

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 :)

Dustin Ingram
  • 20,502
  • 7
  • 59
  • 82
a_mazz
  • 73
  • 1
  • 3

1 Answers1

3

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.

Waelmas
  • 1,894
  • 1
  • 9
  • 19
  • This is a good answer, but not the problem here-- I now have it printing Content-Length from the request header and I've got one that's 0.03 MB that ended with a connection error. I'd also be surprised that it delivered the request at all if it exceeded GCP's limit. – a_mazz Jan 28 '20 at 18:02
  • Good call, I changed the if else conditions and it returns the connection error if it's `[Type 1]`, regardless of what it is. So it doesn't seem like it's an issue with the Github payload itself. I'll try GAE later and see what happens there! – a_mazz Jan 29 '20 at 16:48
  • 1
    It does appear to work fine on GAE, so I'm marking this as the answer. Thanks!! – a_mazz Feb 11 '20 at 15:21