googlearchive / cloud-functions-go

Unofficial Native Go Runtime for Google Cloud Functions
Apache License 2.0
423 stars 44 forks source link

Error: could not handle the request #31

Open montanaflynn opened 6 years ago

montanaflynn commented 6 years ago

Getting this plain text response every 30 or so requests:

Error: could not handle the request

Checking the server logs I found this:

severity:  "ERROR"  
textPayload:  "Error: function crashed out of request scope
 Function invocation was interrupted.
" 
iangudger commented 6 years ago

There are no known issues that would cause this. Are you sure that it isn't a bug in your app?

montanaflynn commented 6 years ago

I never get the error when testing with (make test) or making the handler from the golang net/http server. I did find a similar issue: https://github.com/firebase/functions-samples/issues/78 but that's for javascript.

My handler encodes a png image and writes it to http.ResponseWriter, here's the entire app.

Here is more error information from the logs:

Function execution took 284 ms, finished with status: 'connection error'
iangudger commented 6 years ago

Can you try removing the use of the nodego logger and see if that fixes the problem?

By the way, when you add the logging back, you should add the nodego.WithLoggerFunc middleware. That way your logs will get associated with the request that triggered them. See examples/logging.go.

montanaflynn commented 6 years ago

Removing the nodego logger does seem to fix the issue.

The problem remains even when using the nodego.WithLoggerFunc middleware. When using the middleware should I not use nodego.ErrorLogger.Println(err)? If I use Go's std log then I miss out on the error / info abstraction.

montanaflynn commented 6 years ago

Nevermind the problem remains even without the logs, just took over a hundred requests before it happened.

https://gist.github.com/montanaflynn/bb002f8212e9cc7f75af5cc03e7a5fd8

...
HTTP/1.1 200     3.66 secs:    7742 bytes ==> GET  /img-without-logs
HTTP/1.1 500     3.68 secs:      36 bytes ==> GET  /img-without-logs
HTTP/1.1 200     0.84 secs:    7742 bytes ==> GET  /img-without-logs
...
montanaflynn commented 6 years ago

I removed any third party packages and can reproduce with standard library:

This code returns the error / 500 response every so often. This code does not return an error / 500 response afaik.

The difference in the code that doesn't return an error is I removed all the nodego logger code including init nodego.OverrideLogger() and nodego.WithLoggerFunc middleware wrapper.

iangudger commented 6 years ago

It seems that the problem could still be logging as you include nodego.OverrideLogger() in the problematic one, but not the non-problematic one.

iangudger commented 6 years ago

By the way, you can use nodego.ErrorLogger with nodego.WithLoggerFunc. Maybe we need to clarify the documentation.

marcelogrsp commented 5 years ago

Hi all, I am getting the same error. It works when Testing but doesn't work when I send HTTP POST request. Actually it works via POST request after I send 3 or more requests.

iangudger commented 5 years ago

Cloud Functions now has official Go support: https://cloud.google.com/functions/docs/quickstart#functions-update-install-gcloud-go

As a result, this repository is no longer under active development. Pull requests are still welcome though.