Skip to content

bug: grpc-transcode's pb_option is set on the proto level #7025

@spacewander

Description

@spacewander

Current Behavior

The pb.option method in lua-protobuf is set on the pb_State object, which is mapped from the proto object in APISIX. Therefore, setting the option will affect other routes which share the same proto.

Setting the option globally won't affect grpc-transcode as each proto has its own pb_State.

Expected Behavior

No response

Error Logs

No response

Steps to Reproduce

The test case below shows it:

=== TEST 12: set routes(id: 2)
--- ONLY
--- config
    location /t {
        content_by_lua_block {
            local t = require("lib.test_admin").test
            local code, body = t('/apisix/admin/routes/1',
                ngx.HTTP_PUT,
                [[{
                    "methods": ["GET"],
                    "uri": "/grpc_plus2",
                    "plugins": {
                        "grpc-transcode": {
                            "proto_id": "1",
                            "service": "helloworld.Greeter",
                            "method": "Plus"
                        }
                    },
                    "upstream": {
                        "scheme": "grpc",
                        "type": "roundrobin",
                        "nodes": {
                            "127.0.0.1:50051": 1
                        }
                    }
                }]]
            )
            local code, body = t('/apisix/admin/routes/2',
                ngx.HTTP_PUT,
                [[{
                    "methods": ["GET"],
                    "uri": "/grpc_plus",
                    "plugins": {
                        "grpc-transcode": {
                            "proto_id": "1",
                            "service": "helloworld.Greeter",
                            "method": "Plus",
                            "pb_option":["int64_as_string", "enum_as_name"]
                        }
                    },
                    "upstream": {
                        "scheme": "grpc",
                        "type": "roundrobin",
                        "nodes": {
                            "127.0.0.1:50051": 1
                        }
                    }
                }]]
            )

            if code >= 300 then
                ngx.status = code
            end
            ngx.say(body)

            local http = require "resty.http"
            local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/grpc_plus?a=1&b=2251799813685260"
            local httpc = http.new()
            local res, err = httpc:request_uri(uri)
            ngx.say(res.body)
            local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/grpc_plus2?a=1&b=2251799813685260"
            local httpc = http.new()
            local res, err = httpc:request_uri(uri)
            ngx.say(res.body)
        }
    }
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]

The route configurations of /grpc_plus & /grpc_plus2 are different, but now they provide the same result because of the pollution.

Environment

  • APISIX version (run apisix version): 2.13.1
  • Operating system (run uname -a): Linux DESKTOP-2022Q8F-wsl 4.19.128-microsoft-standard
  • OpenResty / Nginx version (run openresty -V or nginx -V): nginx version: openresty/1.19.9.1
  • 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):

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions