title: Google Cloud Function finished with status: 'connection error'
body: <p>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.</p>
  
  <p>Here's the function:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>In the logs it shows up as:</p>
  
  <pre><code>"This is not a pull request"
  "Function execution took 11 ms, finished with status: 'connection error'" 
  </code></pre>
  
  <p>And on the Github side the response is an HTTP/500 error with the message "Error: could not handle the request".</p>
  
  <p>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 :)</p>