Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emulator raises "GET" ... "Invalid request, unable to process." on first function call #130

Closed
ekalosak opened this issue Aug 26, 2023 · 6 comments
Labels
waiting for customer response Issue is on hold awaiting more information from OP

Comments

@ekalosak
Copy link
Contributor

This error pops up every time I call a function after starting the emulators.

... [call stack omitted]                                                                                                     
>  Message: 'Request has invalid method.'                                               
>  Arguments: ('GET',)                                                                                                                                                          
>  ERROR:root:Invalid request, unable to process.

I'm using an @https_fn.on_call and calling it with curl -X POST so the GET in there is a bit confusing. Moreover, this just shows up - it doesn't degrade functionality much aside from potentially delaying the cold-start.

The functions work just fine... but this long stack trace on a cold-start is troubling.

@exaby73
Copy link
Contributor

exaby73 commented Aug 28, 2023

Hello @ekalosak. Could you provide a minimal reproducible example as well as your python version and contents of your requirements.txt?

@exaby73 exaby73 added the waiting for customer response Issue is on hold awaiting more information from OP label Aug 28, 2023
@berengamble
Copy link

berengamble commented Sep 11, 2023

It's probably the healthcheck. To deal with it, I just put this in my https functions:

    if req.method == "GET" and req.path == "/__/health":
        logger.debug("Returning OK to healthcheck")
        return https_fn.Response("OK")

If it's not that, print req.path to find out what it is.

@exaby73
Copy link
Contributor

exaby73 commented Sep 11, 2023

@ekalosak Sorry if I misunderstood the issue, but does #134 fix this issue? Seems unrelated to me.

If indeed the issue is this extra GET request triggering the warning log with the None request body, we should probably either try to fix that or if it's not something we can control, at least document it. The PR is still valid, just not sure if this issue should be considered fixed once that's merged in

@ekalosak
Copy link
Contributor Author

ekalosak commented Sep 11, 2023

@exaby73 That strikes me as correct.

The next line above in the stack trace is:

/.../venv/lib/python3.11/site-packages/firebase_functions/private/util.py", line 125, in _on_call_valid_
method
>      _logging.warning("Request has invalid method.", request.method)

While I believe you are quite right that #134 will not fix the reported error, I believe the fix is something quite similar. The offending line is in the same util.py.

minimal reproducible example

python -c 'import logging; logging.warning("won't work", ("GET",))'

expected result

--- Logging error ---
Traceback (most recent call last):
  File "/.../3.11.4/lib/python3.11/logging/__init__.py", line 1110, in emit
    msg = self.format(record)
          ^^^^^^^^^^^^^^^^^^^
  File "/.../3.11.4/lib/python3.11/logging/__init__.py", line 953, in format
    return fmt.format(record)
           ^^^^^^^^^^^^^^^^^^
  File "/.../3.11.4/lib/python3.11/logging/__init__.py", line 687, in format
    record.message = record.getMessage()
                     ^^^^^^^^^^^^^^^^^^^
  File "/.../3.11.4/lib/python3.11/logging/__init__.py", line 377, in getMessage
    msg = msg % self.args
          ~~~~^~~~~~~~~~~
TypeError: not all arguments converted during string formatting
Call stack:
  File "<string>", line 1, in <module>
Message: 'asdf'
Arguments: (('GET',),)

Notice that string coercion fails for tuples.

So that's an easy fix of course, just extract the string value from the 1-tuple request.method and 🚀


Regarding the GET request - as berengamble says above that seems likely to be a desirable health check. The desired behavior, I imagine, aught not to be to remove the health check but instead to fix the error in the utility that logs such requests.

@ekalosak
Copy link
Contributor Author

Fix: #138

@ekalosak
Copy link
Contributor Author

Fixed by merge of #138 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for customer response Issue is on hold awaiting more information from OP
Projects
None yet
Development

No branches or pull requests

3 participants