kong
kong copied to clipboard
Incorrect status code 500 for invalid JSON data processed by grpc-gateway plugin
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
Any update for this?
Hello @manas-gupta-m,
can you supply us with the error message that is logged in Kong's error.log file?
Thank you, Hans
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 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.
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.
Internal tracking ID (for maintainers reference): KAG-847.
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 A contributing PR would be welcome, as we've not been able to make fixing this issue a priority to us at this point.
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 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.
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…
@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?