You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "wklken (via GitHub)" <gi...@apache.org> on 2023/04/24 15:22:57 UTC

[GitHub] [apisix] wklken opened a new issue, #9366: bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match

wklken opened a new issue, #9366:
URL: https://github.com/apache/apisix/issues/9366

   ### Current Behavior
   
   Add two route, 
   - `short`: `GET /api/prod/:version/test/*`
   - `long`: `GET /api/prod/:version/test/api/portal/projects/:project_id_/clusters/:cluster_id/nodes/?`
   
   and `curl -vv http://{}:{}/api/prod/v4/test/api/portal/projects/saas/clusters/123/nodes/`
   
   if
   - add route `short` first, then add route `long` => the request will match route `short`
   - add route `long` first, then add route `short` => the request will match route `long`
   
   
   ```
   apisix:
     router:
       http: radixtree_uri_with_parameter
   ``
   
   
   
   ### Expected Behavior
   
   the curl should always match the route `long`
   
   We tested the same route in golang(use [chi](https://github.com/go-chi/chi), always match the `long`
   
   But in apisix 2.15.1 / 2.15.3 / 3.2.0, the adding order always affect the route match;
   
   
   
   ### Error Logs
   
   no error logs
   
   ### Steps to Reproduce
   
   1. apisix config
   ```yaml
   apisix:
     router:
       http: radixtree_uri_with_parameter
   deployment:
     role: traditional
     role_traditional:
       config_provider: etcd
     admin:
       admin_key:
         - name: bk-apigateway
           key: nAUkdPjuIiAlVBKkWNsfRNpV7Eh3NZIw
           role: admin
       allow_admin: # http://nginx.org/en/docs/http/ngx_http_access_module.html#allow
         - ::/64
         - 127.0.0.0/24
       admin_listen: # use a separate port
         ip: 127.0.0.1
         port: 9180
   ```
   
   2. delete the route via api
   ```bash
   curl -XDELETE 'http://127.0.0.1:9180/apisix/admin/routes/test.1'  -H 'X-API-KEY: nAUkdPjuIiAlVBKkWNsfRNpV7Eh3NZIw'
   curl -XDELETE 'http://127.0.0.1:9180/apisix/admin/routes/test.2'  -H 'X-API-KEY: nAUkdPjuIiAlVBKkWNsfRNpV7Eh3NZIw'
   ```
   
   3. add route `short` first, then add `long`
   ```bash
   curl -XPUT 'http://127.0.0.1:9180/apisix/admin/routes/test.1'  -H 'X-API-KEY: nAUkdPjuIiAlVBKkWNsfRNpV7Eh3NZIw' -d '{
       "name": "prod-short",
       "plugins": {
          "mocking": {
             "content_type": "application/json",
             "response_status": 200,
             "response_example": "short"
          }
       },
       "uris": [
         "/api/prod/:version/test",
         "/api/prod/:version/test/*subpath_match_param_name"
       ],
       "status": 1,
       "methods": [
         "GET"
       ],
       "timeout": {
         "send": 30,
         "read": 30,
         "connect": 30
       },
       "create_time": 1682336180,
       "update_time": 1682345264,
       "id": "test.1",
       "upstream": {
           "type": "roundrobin",
           "nodes": {
               "127.0.0.1:1980": 1
           }
       }
     }'
   ```
   
   ```bash
   curl -XPUT 'http://127.0.0.1:9180/apisix/admin/routes/test.2'  -H 'X-API-KEY: nAUkdPjuIiAlVBKkWNsfRNpV7Eh3NZIw' -d '{
       "name": "prod-long",
       "plugins": {
          "mocking": {
             "content_type": "application/json",
             "response_status": 200,
             "response_example": "long"
          }
       },
       "status": 1,
       "timeout": {
         "send": 30,
         "read": 30,
         "connect": 30
       },
       "methods": [
         "GET"
       ],
       "uri": "/api/prod/:version/test/api/portal/projects/:project_id_/clusters/:cluster_id/nodes/?",   
       "create_time": 1682336179,
       "update_time": 1682345264,
       "id": "test.2",
       "upstream": {
           "type": "roundrobin",
           "nodes": {
               "127.0.0.1:1980": 1
           }
       }
     }'
   ```
   
   4. then curl, will got `response.body=short`
   ```bash
   curl 'http://{ip}:{port}/api/prod/v4/test/api/portal/projects/saas/clusters/123/nodes/'
   short
   ```
   
   5. delete both route, then use the command in step `3`, but change the order, add route `long` first, then add route `short`
   
   6. then curl, will got `response.body=long`
   ```bash
   curl 'http://{ip}:{port}/api/prod/v4/test/api/portal/projects/saas/clusters/123/nodes/'
   long
   ```
   
   
   
   ### Environment
   
   - APISIX version (run `apisix version`):  3.2.0 / 2.15.1 / 2.15.3 (same `lua-resty-radixtree = 2.8.2`)
   - Operating system (run `uname -a`): 
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`): openresty/1.21.4.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`): 3.8.0
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match [apisix]

Posted by "shreemaan-abhishek (via GitHub)" <gi...@apache.org>.
shreemaan-abhishek commented on issue #9366:
URL: https://github.com/apache/apisix/issues/9366#issuecomment-1875031504

   I just attempted on reproducing this issue, irrespective of the order of adding the routes the `short` route got matched. @wklken do you have any say on this?
   
   ```shell
   curl -X PUT 'http://127.0.0.1:9180/apisix/admin/routes/test.2' -H "X-API-KEY: ${ADMIN_API_KEY}" -d '{
       "plugins": {
          "mocking": {
             "content_type": "application/json",
             "response_status": 200,
             "response_example": "long"
          }
       },
       "uri": "/api/prod/:version/test/api/portal/projects/:project_id_/clusters/:cluster_id/nodes/?",
       "upstream": {
           "type": "roundrobin",
           "nodes": {
               "127.0.0.1:1980": 1
           }
       }
     }'
   
   curl -X PUT 'http://127.0.0.1:9180/apisix/admin/routes/test.1' -H "X-API-KEY: ${ADMIN_API_KEY}" -d '{
       "plugins": {
          "mocking": {
             "content_type": "application/json",
             "response_status": 200,
             "response_example": "short"
          }
       },
       "uris": [
         "/api/prod/:version/test",
         "/api/prod/:version/test/*subpath_match_param_name"
       ],
       "upstream": {
           "type": "roundrobin",
           "nodes": {
               "127.0.0.1:1980": 1
           }
       }
     }'
   ```
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match [apisix]

Posted by "shreemaan-abhishek (via GitHub)" <gi...@apache.org>.
shreemaan-abhishek closed issue #9366: bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match
URL: https://github.com/apache/apisix/issues/9366


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match [apisix]

Posted by "shreemaan-abhishek (via GitHub)" <gi...@apache.org>.
shreemaan-abhishek commented on issue #9366:
URL: https://github.com/apache/apisix/issues/9366#issuecomment-1900075377

   radix-tree version in apisix still needs an update


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] Revolyssup commented on issue #9366: bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match

Posted by "Revolyssup (via GitHub)" <gi...@apache.org>.
Revolyssup commented on issue #9366:
URL: https://github.com/apache/apisix/issues/9366#issuecomment-1695283728

   @wklken So the issue is with lua-resty-radixtree, right? Have you opened an issue there?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] wklken commented on issue #9366: bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match

Posted by "wklken (via GitHub)" <gi...@apache.org>.
wklken commented on issue #9366:
URL: https://github.com/apache/apisix/issues/9366#issuecomment-1695310456

   > https://github.com/TencentBlueKing/blueking-apigateway-operator/blob/60f0cd4c1ea59b169ba47e55b23a6af8d2dabf8c/pkg/commiter/conversion/resource.go#L61C6-L61C40
   
   I just open issue here. 
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] wklken commented on issue #9366: bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match

Posted by "wklken (via GitHub)" <gi...@apache.org>.
wklken commented on issue #9366:
URL: https://github.com/apache/apisix/issues/9366#issuecomment-1541206696

   
   after check [lua-resty-radixtree](https://github.com/api7/lua-resty-radixtree) and [chi router](https://github.com/go-chi/chi)
   
   Conclusion:
   
   1. Without any parameters and subpath, the result is independent of the registration order, and the longest match is used.
       - path: `/api/test/prod/test`
       - path: `/api/test/prod/`
   2. Without any parameters, but with subpath, the result is independent of the registration order, and the longest match is used.
       - path: `/api/test/prod/*subp`
       - path: `/api/test/prod/webconsole/*subp`
   3. With parameters and subpath, the result is dependent on the registration order and is not the longest match (this is not an issue with the golang version of radixtree).
       - path: `/api/test/prod/:v/*subp`
       - path: `/api/test/prod/:v/webconsole/*subp`
       - path: `/api/test/prod/v4/webconsole/*subp`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] wklken commented on issue #9366: bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match

Posted by "wklken (via GitHub)" <gi...@apache.org>.
wklken commented on issue #9366:
URL: https://github.com/apache/apisix/issues/9366#issuecomment-1521087621

   If the long route only has one param in its path (e.g. /api/prod/:version/test/api/portal/projects/?), then the curl command will always match the long route. In other words, it seems that the radixtree library does not currently support multiple parameters in the path for matching.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] piglei commented on issue #9366: bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match

Posted by "piglei (via GitHub)" <gi...@apache.org>.
piglei commented on issue #9366:
URL: https://github.com/apache/apisix/issues/9366#issuecomment-1538245405

   Have there been any updates on this?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match [apisix]

Posted by "wklken (via GitHub)" <gi...@apache.org>.
wklken commented on issue #9366:
URL: https://github.com/apache/apisix/issues/9366#issuecomment-1880288208

   I have reproduced via https://github.com/apache/apisix-docker.git  @shreemaan-abhishek 
   
   ```
   git pull https://github.com/apache/apisix-docker.git
   
   cd apisix-docker
   
   vim compose/apisix_conf/master/config.yaml
   
   # router:
   #   http: radixtree_uri_with_parameter
   
   vim docker-compose-master.yaml 
   
   # image: "apache/apisix:3.2.1-centos"
   
   docker-compose -p docker-apisix -f docker-compose-master.yaml up 
   ```
   
   then  `docker exec -it dockerapisix_apisix_1 /bin/bash`
   
   ```
   curl -XDELETE 'http://127.0.0.1:9180/apisix/admin/routes/test.1'  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1'
   curl -XDELETE 'http://127.0.0.1:9180/apisix/admin/routes/test.2'  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1'
   
   curl -XPUT 'http://127.0.0.1:9180/apisix/admin/routes/test.1'  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -d '{
       "name": "prod-short",
       "plugins": {
          "mocking": {
             "content_type": "application/json",
             "response_status": 200,
             "response_example": "short"
          }
       },
       "uris": [
         "/api/prod/:version/test",
         "/api/prod/:version/test/*subpath_match_param_name"
       ],
       "status": 1,
       "methods": [
         "GET"
       ],
       "timeout": {
         "send": 30,
         "read": 30,
         "connect": 30
       },
       "create_time": 1682336180,
       "update_time": 1682345264,
       "id": "test.1",
       "upstream": {
           "type": "roundrobin",
           "nodes": {
               "127.0.0.1:1980": 1
           }
       }
     }'
   
   
   curl -XPUT 'http://127.0.0.1:9180/apisix/admin/routes/test.2'  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -d '{
       "name": "prod-long",
       "plugins": {
          "mocking": {
             "content_type": "application/json",
             "response_status": 200,
             "response_example": "long"
          }
       },
       "status": 1,
       "timeout": {
         "send": 30,
         "read": 30,
         "connect": 30
       },
       "methods": [
         "GET"
       ],
       "uri": "/api/prod/:version/test/api/portal/projects/:project_id_/clusters/:cluster_id/nodes/?",   
       "create_time": 1682336179,
       "update_time": 1682345264,
       "id": "test.2",
       "upstream": {
           "type": "roundrobin",
           "nodes": {
               "127.0.0.1:1980": 1
           }
       }
     }'
   
   
   curl 'http://0.0.0.0:9080/api/prod/v4/test/api/portal/projects/saas/clusters/123/nodes/'
   ```
   
   same order, hit `short`; change the order, hit the `long`
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] wklken commented on issue #9366: bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match

Posted by "wklken (via GitHub)" <gi...@apache.org>.
wklken commented on issue #9366:
URL: https://github.com/apache/apisix/issues/9366#issuecomment-1521111485

   change 
   - `short` to `/api/prod/:version/test/*subpath_match_param_name`
   - `long` to `/api/prod/:version/test/api/?`
   
   the result still the same. 
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] wklken commented on issue #9366: bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match

Posted by "wklken (via GitHub)" <gi...@apache.org>.
wklken commented on issue #9366:
URL: https://github.com/apache/apisix/issues/9366#issuecomment-1521173847

   ```lua
      local rx = radix.new({
               {
                   paths = {"/api/prod/:version/test/api/foo/?"},
                   metadata = "metadata long",
               },
               {
                   paths = {"/api/prod/:version/test/*subp"},
                   metadata = "metadata short",
               },
           })
   
       local opts = {
               host = "foo.com",
               method = "GET",
               remote_addr = "127.0.0.1",
               vars = ngx.var,
       }
       local path = "/api/prod/v4/test/api/foo/"
       local metadata = rx:match(path, opts)
       core.log.error(metadata)
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match [apisix]

Posted by "wklken (via GitHub)" <gi...@apache.org>.
wklken commented on issue #9366:
URL: https://github.com/apache/apisix/issues/9366#issuecomment-1875132762

   did you set the 'http: radixtree_uri_with_parameter'? and what the apisix version? @shreemaan-abhishek 
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] wklken commented on issue #9366: bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match

Posted by "wklken (via GitHub)" <gi...@apache.org>.
wklken commented on issue #9366:
URL: https://github.com/apache/apisix/issues/9366#issuecomment-1663250854

   https://github.com/TencentBlueKing/blueking-apigateway-operator/blob/60f0cd4c1ea59b169ba47e55b23a6af8d2dabf8c/pkg/commiter/conversion/resource.go#L61C6-L61C40
   
   we set the `priority` to fix the issue; make it act like `the longest path match`
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match [apisix]

Posted by "shreemaan-abhishek (via GitHub)" <gi...@apache.org>.
shreemaan-abhishek closed issue #9366: bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match
URL: https://github.com/apache/apisix/issues/9366


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match [apisix]

Posted by "shreemaan-abhishek (via GitHub)" <gi...@apache.org>.
shreemaan-abhishek commented on issue #9366:
URL: https://github.com/apache/apisix/issues/9366#issuecomment-1877258070

   yep, tried with v3.2.1 as well. Result is the same.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match [apisix]

Posted by "shreemaan-abhishek (via GitHub)" <gi...@apache.org>.
shreemaan-abhishek commented on issue #9366:
URL: https://github.com/apache/apisix/issues/9366#issuecomment-1875298157

   yes I did.
   
   I tested on master.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] bug: Adding routes to a Radix Tree in a different order can lead to the same URL matching the first added route instead of the longest path match [apisix]

Posted by "wklken (via GitHub)" <gi...@apache.org>.
wklken commented on issue #9366:
URL: https://github.com/apache/apisix/issues/9366#issuecomment-1875485014

   I tested it again, and I can reproduce it following the `Steps to Reproduce`, the apisix version is 3.2.1
   
   the radix lib of master is the same `lua-resty-radixtree = 2.8.2`
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org