apisix
apisix copied to clipboard
help request: grpc request proxy http code must be 599 when request not success
Description
I use apisix for grpc proxy。I use a custom lua plugin to process the request,when some request param not right,i return code like:
core.response.add_header("Content-Type", "application/grpc")
core.response.add_header("grpc-status", "16")
core.response.add_header("grpc-message", "UNAUTHENTICATED")
return 200
and I use a grpc tool "bloom-rpc" to debug the request,then the "bloom-rpc" return like
"error": "2 UNKNOWN: No status received"
and I tried golang client to debug,it returns err server closed the stream without sending trailers。
I don't know why,and i debuged a whole day。。。
and when i set the status code 200 -> 599,it worked。。 so i what know why?
and another question,it works well in kong the code like that
return kong.response.exit(200, nil, {
["Content-Type"] = "application/grpc",
["grpc-status"] = 16,
["grpc-message"] = "UNAUTHENTICATED"
})
Hope the answer! Thanks very well!
Environment
- APISIX version (run
apisix version):2.13 - Operating system (run
uname -a):centos os 7.9 - OpenResty / Nginx version (run
openresty -Vornginx -V): - etcd version, if relevant (run
curl http://127.0.0.1:9090/v1/server_info): - APISIX Dashboard version, if relevant:
- Plugin runner version, for issues related to plugin runners:
- LuaRocks version, for installation issues (run
luarocks --version):
@caozhi6655 Could you give a reproducible case? The custom plugin is vital and could you paste more codes about it?
You can remove all the private, business-related logic but the basic logic should be reserved, such as in which phase this plugin will be called.
And the route and upstream objects are expected.
@caozhi6655 Could you give a reproducible case? The custom plugin is vital and could you paste more codes about it?
You can remove all the private, business-related logic but the basic logic should be reserved, such as in which phase this plugin will be called.
And the route and upstream objects are expected.
@tokers upstream like this
{
"nodes": [
{
"host": "xxx",
"port": xxx,
"weight": 1
}
],
"timeout": {
"connect": 6,
"send": 6,
"read": 6
},
"type": "roundrobin",
"scheme": "grpc",
"pass_host": "pass",
"name": "proto.user.UserService-upstream",
"keepalive_pool": {
"idle_timeout": 60,
"requests": 1000,
"size": 320
}
}
route like this
path: /proto.user.UserService/*
upstream:proto.user.UserService-upstream`
lua plugin like this
`function _M.rewrite(conf, ctx)
if token then
xxx
else
core.response.add_header("Content-Type", "application/grpc")
core.response.add_header("grpc-status", "16")
core.response.add_header("grpc-message", "UNAUTHENTICATED")
return 200
end
end
@tokers Did this reappeared in your code?
It looks like APISIX does not support using core.response directly in the plugin to process and return gRPC related requests.
It looks like APISIX does not support using
core.responsedirectly in the plugin to process and return gRPC related requests.
ngx can't too
If you add these response headers before APISIX forwards gRPC messages to the backend, these headers will be overwritten by the gRPC proxy module.
Try the header filter module.
Could you explain it more?I can't catch you,or can you show me the code or configs with header filter module?
https://github.com/apache/apisix/blob/3b1cda748700d915bce4d2e6294321fc5589374e/apisix/plugins/grpc-transcode.lua#L149-L168
This issue has been marked as stale due to 350 days of inactivity. It will be closed in 2 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.
This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.