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