Skip to content Skip to sidebar Skip to footer

Random Connection Error In Google Cloud Functions (python)

Because I have been getting some unexpected CORS errors in my browser console for the past few weeks, I have set up a super simple Python script with a single function inside Googl

Solution 1:

UPDATE

After digging further, we realized that the problem is actually a bug in the Google Cloud Function service. This bug affects specifically cloud functions using the Python runtime. Those functions will raise a connection error (and will return code 500) if they get an HTTP POST request with a body larger than ~10 KB. Interestingly though, this won't happen in every request with such characteristics, but in most of them.

The Google support service was informed about this issue and they acknowledged the bug. They created a public issue in their issue tracker that should be updated with additional information according to the progress of the solution. By the day of this writing the issue is marked as "New".

Workaround: as suggested by @Timon, it seems that calling request.get_json() in the function seems to fix the issue for requests with JSON bodies. This won't work if the body of your request uses a different format.


OLD ANSWER

I just set up a clean GC Function with the exact same code you provided and it worked flawlessly. I can make requests through the browser (using your JS code) and they never fail.

This leave us with two options:

  1. There is something in your browser or your internet connection that is causing some of your requests to fail.
  2. There is something in your GCF that is causing errors.

For option 1 check this:

  • Do the failed requests occur in batches? Or they are randomly sampled? If they occur in batches the problem could be your internet connection.
  • Are you using some sort of VPN or proxy? Try disabling it.
  • Have you tried multiple browsers? If not, try. Is the described behaviour the same in all of them?

For option 2, check this:

  • Is your function the exact same code you published? If not, and it has more code, the problem is probably there.
  • Do you deploy your function using some command line tool? Is yes, try to do it through the inline editor in GCP website.
  • In the networking setting of your function (in advanced settings), be sure to select "Allow all traffic"

Solution 2:

I fixed this issue by increasing the RAM allocated to the Cloud Function. Mine had 512MB when this issue was occurring. I increased it to 1GB and it started working like a charm.

Post a Comment for "Random Connection Error In Google Cloud Functions (python)"