kong icon indicating copy to clipboard operation
kong copied to clipboard

Incorrect status code 500 for invalid JSON data processed by grpc-gateway plugin

Open manas-gupta-m opened this issue 1 year ago • 12 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Kong version ($ kong version)

Kong 2.8.1

Current Behavior

When I send an invalid JSON request, or a valid JSON with incorrect data type for a certain field, the response is received as a stream with 500 internal server error.

Expected Behavior

When I send an invalid JSON request, or a valid JSON with incorrect data type for a certain field, the response should be 400 with proper JSON response.

Steps To Reproduce

1. Add kong grpc-gateway plugin in declarative yml, and add proto path to config.
2. Start Kong server
3. Send HTTP request with Invalid JSON, or incorrect datatype in JSON.

Anything else?

No response

manas-gupta-m avatar Dec 30 '22 07:12 manas-gupta-m

Any update for this?

manas-gupta-m avatar Jan 23 '23 09:01 manas-gupta-m

Hello @manas-gupta-m,

can you supply us with the error message that is logged in Kong's error.log file?

Thank you, Hans

hanshuebner avatar Jan 23 '23 10:01 hanshuebner

Hi @hanshuebner

I am getting the following error log when trying to hit a request with invalid JSON (explicitly removing ending curly brace from request):

==> /opt/homebrew/Cellar/kong/3.1.1/logs/error.log <==
2023/01/23 18:12:49 [error] 22203#0: *32951 [kong] init.lua:333 [grpc-gateway] ...omebrew/share/lua/5.1/kong/plugins/grpc-gateway/deco.lua:227: Expected comma or object end but found T_END at character 1412, client: 127.0.0.1, server: kong, request: "POST /orchestrator/hotel/bookingPush HTTP/1.1", host: "localhost:8000"

Along with that, the response is continuously going in an endless stream with 500 status code, whereas expected behaviour is that it should print the above log message in response with 400 status code.

I even tried looking into the handler.lua file of grpc-gateway, there seems to be some problem with body-filter phase of the grpc-gateway plugin. When I commented that out, it was working.

manas-gupta-m avatar Jan 23 '23 12:01 manas-gupta-m

@manas-gupta-m Thank you for the clarification. This is a bug in the grpc-gateway plugin, and we are tracking it in our bug tracking system. We cannot make a firm promise when we'll be able to fix it, but you are welcome to send a pull request with a fix.

hanshuebner avatar Jan 23 '23 14:01 hanshuebner

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 10 '23 06:02 stale[bot]

Internal tracking ID (for maintainers reference): KAG-847.

gszr avatar Mar 10 '23 17:03 gszr

We’ve seen a similar failure when sending a JSON boolean to gRPC fields declared as optional string:

2024-01-16 18:11:18.615	2024/01/17 02:11:18 [error] 1249#0: *1606 [kong] init.lua:354 [grpc_gateway] /usr/local/share/lua/5.1/kong/plugins/grpc_gateway/deco.lua:383: bad argument #2 to 'encode' (string expected for field 'email', got boolean), client: 192.168.65.3, server: kong, request: "POST /foo/bar/ HTTP/1.1", host: "kubernetes.local:8000

@hanshuebner would you be open to a contribution?

jenstroeger avatar Jan 18 '24 21:01 jenstroeger

@jenstroeger A contributing PR would be welcome, as we've not been able to make fixing this issue a priority to us at this point.

hanshuebner avatar Jan 19 '24 02:01 hanshuebner

A contributing PR would be welcome, as we've not been able to make fixing this issue a priority to us at this point.

Thanks @hanshuebner. I’m currently following the Build and Install from source instructions but I might be better off using Linux instead of Mac. I use port instead of brew and would have to tweak the build scripts a little, and could use a little guidance. How responsive are the Discussions?

jenstroeger avatar Jan 19 '24 05:01 jenstroeger

@jenstroeger Homebrew seems to be the first choice for most Mac users nowadays, but if MacPorts can easily be supported as well, feel free to send a PR.

Maybe ask in the Discussions section whether there are any other users interested in MacPorts.

Linux is a safe choice for development purposes in any case.

hanshuebner avatar Jan 19 '24 06:01 hanshuebner

Linux is a safe choice for development purposes in any case.

I think I’ll stick with that for the time being. Developing inside of a Ubuntu container is stable? Else I’d hop onto a native Gentoo box and work there, but would require the PG and Casandra containers for testing which seems to be supplied…

jenstroeger avatar Jan 19 '24 07:01 jenstroeger

@hanshuebner Hello, sorry to bother you. I have created a pr for this issue and there was already one approved member. One more member is needed. So I just need to wait for another member to review it? How long will it usually cost?

beardnick avatar May 01 '24 07:05 beardnick