cloud-functions-go icon indicating copy to clipboard operation
cloud-functions-go copied to clipboard

Error: could not handle the request

Open montanaflynn opened this issue 6 years ago • 10 comments

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.
" 

montanaflynn avatar Feb 27 '18 04:02 montanaflynn

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

iangudger avatar Feb 27 '18 04:02 iangudger

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'

montanaflynn avatar Feb 27 '18 08:02 montanaflynn

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.

iangudger avatar Feb 27 '18 11:02 iangudger

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 avatar Feb 27 '18 18:02 montanaflynn

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 avatar Feb 27 '18 18:02 montanaflynn

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.

montanaflynn avatar Feb 27 '18 19:02 montanaflynn

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 avatar Feb 27 '18 19:02 iangudger

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

iangudger avatar Feb 27 '18 21:02 iangudger

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.

marcelogrsp avatar May 09 '19 21:05 marcelogrsp

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.

iangudger avatar May 09 '19 21:05 iangudger