You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/08/06 07:27:11 UTC

[GitHub] [apisix] membphis opened a new issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

membphis opened a new issue #2006:
URL: https://github.com/apache/apisix/issues/2006


   APISIX version: 1.5
   
   ```
   2020/08/06 15:15:13 [error] 49#49: *56762 failed to run header_filter_by_lua*: /usr/local/apisix/apisix/core/lrucache.lua:198: attempt to concatenate field 'conf_id' (a nil value)
   stack traceback:
           /usr/local/apisix/apisix/core/lrucache.lua:198: in function 'plugin_ctx'
           /usr/local/apisix/apisix/plugins/cors.lua:144: in function 'phase_fun'
           /usr/local/apisix/apisix/init.lua:142: in function 'run_plugin'
           /usr/local/apisix/apisix/init.lua:550: in function 'common_phase'
           /usr/local/apisix/apisix/init.lua:561: in function 'http_header_filter_phase'
   ```


----------------------------------------------------------------
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.

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



[GitHub] [apisix] membphis removed a comment on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
membphis removed a comment on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-757690967


   @Firstsawyou do you have reproduced this issue?


----------------------------------------------------------------
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.

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



[GitHub] [apisix] ShiningRush commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
ShiningRush commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-732533463


   I will try to produce the bug in master, We have not been able to produce this bug stably before : (


----------------------------------------------------------------
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.

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



[GitHub] [apisix] membphis commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
membphis commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-732201361


   @ShiningRush do you have time to fix this bug?


----------------------------------------------------------------
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.

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



[GitHub] [apisix] griffenliu edited a comment on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
griffenliu edited a comment on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-690836227


   I have the same problem, see #2194.
   
   > ### Issue description
   > when route not found and `return core.response.exit(404, {error_msg = "failed to match any routes"})`, the apisix throw an error.
   > 
   > ### Environment
   > * apisix version (cmd: `apisix version`): 1.5
   > * OS: Ubuntu 18.04
   > 
   > ### Minimal test code / Steps to reproduce the issue
   > 1. add global plugin cors
   > 
   > ```
   > curl -X PUT \
   >   https://{apisix_listen_address}/apisix/admin/global_rules/1 \
   >   -H 'Content-Type: application/json' \
   >   -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
   >   -d '{
   >         "plugins": {
   >             "cors": { }
   >         }
   >     }'
   > ```
   > 
   > 1. Access a nonexistent Route, for example: http://172.0.0.1:9080/test
   > 2. the apisix source code snippet
   > 
   > ```
   > -- ### init.lua
   > function _M.http_access_phase()
   >     .....
   >      -- load and run global rule
   >      if router.global_rules and router.global_rules.values
   >         and #router.global_rules.values > 0 then
   >          local plugins = core.tablepool.fetch("plugins", 32, 0)
   >          local values = router.global_rules.values
   >          for _, global_rule in config_util.iterate_values(values) do
   >              api_ctx.conf_type = "global_rule"
   >              api_ctx.conf_version = global_rule.modifiedIndex
   >              api_ctx.conf_id = global_rule.value.id
   >              core.table.clear(plugins)
   >              api_ctx.plugins = plugin.filter(global_rule, plugins)
   >              run_plugin("rewrite", plugins, api_ctx)
   >              run_plugin("access", plugins, api_ctx)
   >          end
   > 
   >          core.tablepool.release("plugins", plugins)
   >         **--  Note: api_ctx is cleared here
   >          api_ctx.plugins = nil
   >          api_ctx.conf_type = nil
   >          api_ctx.conf_version = nil
   >          api_ctx.conf_id = nil**
   >         
   >          api_ctx.global_rules = router.global_rules
   >      end
   >      .....
   >      -- Note: here no route matched, so exit 404
   >      local route = api_ctx.matched_route
   >      if not route then
   >          return core.response.exit(404,
   >                      {error_msg = "failed to match any routes"})
   >      end
   >      ...
   > end
   > -- Continue with the following code
   >  function _M.http_header_filter_phase()
   >      common_phase("header_filter")
   >  end
   > local function common_phase(phase_name)
   >     ...
   >     if api_ctx.global_rules then
   >          local plugins = core.tablepool.fetch("plugins", 32, 0)
   >          local values = api_ctx.global_rules.values
   >          for _, global_rule in config_util.iterate_values(values) do
   >              core.table.clear(plugins)
   >              plugins = plugin.filter(global_rule, plugins)
   >              -- Note: here run global plugin
   >              run_plugin(phase_name, plugins, api_ctx)
   >          end
   >          core.tablepool.release("plugins", plugins)
   >      end
   >      ...
   > end
   > 
   > local function run_plugin(phase, plugins, api_ctx)
   >     .....
   >     for i = 1, #plugins, 2 do
   >          local phase_fun = plugins[i][phase]
   >          if phase_fun then
   >              phase_fun(plugins[i + 1], api_ctx)
   >          end
   >      end
   >      .....
   > end
   > -- ### cors.lua
   > function _M.header_filter(conf, ctx)
   >     .....
   >     -- Note: here the ctx is api_ctx
   >     local multiple_origin, err = core.lrucache.plugin_ctx(plugin_name, ctx,
   >                                                 create_mutiple_origin_cache, conf)
   >     .....
   > end
   > 
   > -- ### lrucache.lua
   > function _M.plugin_ctx(plugin_name, api_ctx, create_obj_fun, ...)
   >     -- Note: here used api_ctx.conf_id is nil
   >     local key = api_ctx.conf_type .. "#" .. api_ctx.conf_id
   >     return _plugin(plugin_name, key, api_ctx.conf_version, create_obj_fun, ...)
   > end
   > ```
   > 
   > ### What's the actual result? (including assertion message & call stack if applicable)
   > 2020/09/09 11:37:14 [error] 9701#9701: _373 failed to run header_filter_by_lua_: ...user-center//deps/share/lua/5.1/apisix/core/lrucache.lua:202: attempt to concaten ate field 'conf_id' (a nil value)
   > 2297217 stack traceback:
   > 2297218 ...user-center//deps/share/lua/5.1/apisix/core/lrucache.lua:202: in function 'plugin_ctx'
   > 2297219 ...-user-center//deps/share/lua/5.1/apisix/plugins/cors.lua:144: in function 'phase_fun'
   > 2297220 ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:142: in function 'run_plugin'
   > 2297221 ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:562: in function 'common_phase'
   > 2297222 ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:573: in function 'http_header_filter_phase'
   > 2297223 header_filter_by_lua:2: in main chunk, client: 172.30.212.206, server: , request: "GET /dfy-h5-user HTTP/1.0", host: "m.dafangya.com.cn"
   > 
   > ### What's the expected result?
   > 404 page.


----------------------------------------------------------------
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.

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



[GitHub] [apisix] griffenliu edited a comment on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
griffenliu edited a comment on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-694208133


   I want to use the prometheus plug-ins.
   But when I access http://localhost:9080/apisix/prometheus/metrics by document https://github.com/apache/apisix/blob/master/doc/zh-cn/plugins/prometheus.md.
   
   I got the following error too:
   ```
   2020/09/17 20:45:31 [error] 3087#3087: *11669858 failed to run header_filter_by_lua*: ...user-center//deps/share/lua/5.1/apisix/core/lrucache.lua:202: attempt to concatenate
    field 'conf_id' (a nil value)                                                                                                                                               
   stack traceback:                                                                                                                                                             
           ...user-center//deps/share/lua/5.1/apisix/core/lrucache.lua:202: in function 'plugin_ctx'                                                                            
           ...-user-center//deps/share/lua/5.1/apisix/plugins/cors.lua:144: in function 'phase_fun'                                                                             
           ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:142: in function 'run_plugin'
           ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:550: in function 'common_phase'
           ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:561: in function 'http_header_filter_phase'
           header_filter_by_lua:2: in main chunk, client: 172.30.213.200, server: , request: "GET /apisix/prometheus/metrics HTTP/1.1", host: "172.30.212.70:9080"
   ```
   
   


----------------------------------------------------------------
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.

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



[GitHub] [apisix] membphis commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
membphis commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-757690967


   @Firstsawyou do you have reproduced this issue?


----------------------------------------------------------------
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.

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



[GitHub] [apisix] membphis commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
membphis commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-732801208


   > I had the same problem in version 2.0,
   
   please provide your steps about how to produce this issue, we need it. many thx


----------------------------------------------------------------
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.

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



[GitHub] [apisix] ShiningRush edited a comment on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
ShiningRush edited a comment on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-670311269


   @backnero Hi, I have a try in my environment, but does not reproduce the problem, can you give more detail about the bug?such as is route bind custom plugin.


----------------------------------------------------------------
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.

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



[GitHub] [apisix] dickens7 commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
dickens7 commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-756699567


   What is the meaning of this code
   
   > https://github.com/apache/apisix/blob/master/apisix/init.lua#L365-L368
   
   ```lua
   365        api_ctx.plugins = nil
   366        api_ctx.conf_type = nil
   367        api_ctx.conf_version = nil
   368        api_ctx.conf_id = nil
   ```
   
   - apisix 2.1
   ```
   2021/01/08 10:58:50 [error] 79#79: *440247 failed to run header_filter_by_lua*: /usr/local/apisix/apisix/core/lrucache.lua:162: invalid value (nil) at index 1 in table for 'concat'
   stack traceback:
           [C]: in function 'concat'
           /usr/local/apisix/apisix/core/lrucache.lua:162: in function 'plugin_ctx'
           /usr/local/apisix/apisix/plugins/cors.lua:168: in function 'phase_func'
           /usr/local/apisix/apisix/init.lua:160: in function 'run_plugin'
           /usr/local/apisix/apisix/init.lua:615: in function 'common_phase'
           /usr/local/apisix/apisix/init.lua:652: in function 'http_header_filter_phase'
   ```


----------------------------------------------------------------
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.

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



[GitHub] [apisix] membphis commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
membphis commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-675453728


   @backnero you need to provide the parameter of route and SSL object. then we can use it directly.
   
   we need a way to reproduce this issue for fixing.


----------------------------------------------------------------
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.

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



[GitHub] [apisix] dickens7 edited a comment on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
dickens7 edited a comment on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-756699567


   What is the meaning of this code
   
   > https://github.com/apache/apisix/blob/master/apisix/init.lua#L365-L368
   
   ```lua
   365        api_ctx.plugins = nil
   366        api_ctx.conf_type = nil
   367        api_ctx.conf_version = nil
   368        api_ctx.conf_id = nil
   ```
   
   - apisix 2.1 global_rules enable cors plugin, upstream response 404 will cause this problem
   
   ```
   2021/01/08 10:58:50 [error] 79#79: *440247 failed to run header_filter_by_lua*: /usr/local/apisix/apisix/core/lrucache.lua:162: invalid value (nil) at index 1 in table for 'concat'
   stack traceback:
           [C]: in function 'concat'
           /usr/local/apisix/apisix/core/lrucache.lua:162: in function 'plugin_ctx'
           /usr/local/apisix/apisix/plugins/cors.lua:168: in function 'phase_func'
           /usr/local/apisix/apisix/init.lua:160: in function 'run_plugin'
           /usr/local/apisix/apisix/init.lua:615: in function 'common_phase'
           /usr/local/apisix/apisix/init.lua:652: in function 'http_header_filter_phase'
   ```


----------------------------------------------------------------
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.

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



[GitHub] [apisix] dickens7 edited a comment on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
dickens7 edited a comment on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-756699567


   What is the meaning of this code
   
   > https://github.com/apache/apisix/blob/master/apisix/init.lua#L365-L368
   
   ```lua
   365        api_ctx.plugins = nil
   366        api_ctx.conf_type = nil
   367        api_ctx.conf_version = nil
   368        api_ctx.conf_id = nil
   ```
   
   - apisix 2.1 global_rules enable cors plugin, upstream response 404 will cause this problem
   
   ```
   2021/01/08 10:58:50 [error] 79#79: *440247 failed to run header_filter_by_lua*: /usr/local/apisix/apisix/core/lrucache.lua:162: invalid value (nil) at index 1 in table for 'concat'
   stack traceback:
           [C]: in function 'concat'
           /usr/local/apisix/apisix/core/lrucache.lua:162: in function 'plugin_ctx'
           /usr/local/apisix/apisix/plugins/cors.lua:168: in function 'phase_func'
           /usr/local/apisix/apisix/init.lua:160: in function 'run_plugin'
           /usr/local/apisix/apisix/init.lua:615: in function 'common_phase'
           /usr/local/apisix/apisix/init.lua:652: in function 'http_header_filter_phase'
   ```


----------------------------------------------------------------
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.

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



[GitHub] [apisix] ShiningRush commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
ShiningRush commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-694634705


   I think this is the same problem, the key point is related with [this comment](https://github.com/apache/apisix/issues/2006#issuecomment-669769777)


----------------------------------------------------------------
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.

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



[GitHub] [apisix] griffenliu edited a comment on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
griffenliu edited a comment on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-690836227


   I have the same problem, see #2194.
   
   > ### Issue description
   > when route not found and `return core.response.exit(404, {error_msg = "failed to match any routes"})`, the apisix throw an error.
   > 
   > ### Environment
   > * apisix version (cmd: `apisix version`): 1.5
   > * OS: Ubuntu 18.04
   > 
   > ### Minimal test code / Steps to reproduce the issue
   > 1. add global plugin cors
   > 
   > ```
   > curl -X PUT \
   >   https://{apisix_listen_address}/apisix/admin/global_rules/1 \
   >   -H 'Content-Type: application/json' \
   >   -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
   >   -d '{
   >         "plugins": {
   >             "cors": { }
   >         }
   >     }'
   > ```
   > 
   > 1. Access a nonexistent Route, for example: http://172.0.0.1:9080/test
   > 2. the apisix source code snippet
   > 
   > ```
   > -- ### init.lua
   > function _M.http_access_phase()
   >     .....
   >      -- load and run global rule
   >      if router.global_rules and router.global_rules.values
   >         and #router.global_rules.values > 0 then
   >          local plugins = core.tablepool.fetch("plugins", 32, 0)
   >          local values = router.global_rules.values
   >          for _, global_rule in config_util.iterate_values(values) do
   >              api_ctx.conf_type = "global_rule"
   >              api_ctx.conf_version = global_rule.modifiedIndex
   >              api_ctx.conf_id = global_rule.value.id
   >              core.table.clear(plugins)
   >              api_ctx.plugins = plugin.filter(global_rule, plugins)
   >              run_plugin("rewrite", plugins, api_ctx)
   >              run_plugin("access", plugins, api_ctx)
   >          end
   > 
   >          core.tablepool.release("plugins", plugins)
   >         **--  Note: api_ctx is cleared here
   >          api_ctx.plugins = nil
   >          api_ctx.conf_type = nil
   >          api_ctx.conf_version = nil
   >          api_ctx.conf_id = nil**
   >         
   >          api_ctx.global_rules = router.global_rules
   >      end
   >      .....
   >      -- Note: here no route matched, so exit 404
   >      local route = api_ctx.matched_route
   >      if not route then
   >          return core.response.exit(404,
   >                      {error_msg = "failed to match any routes"})
   >      end
   >      ...
   > end
   > -- Continue with the following code
   >  function _M.http_header_filter_phase()
   >      common_phase("header_filter")
   >  end
   > local function common_phase(phase_name)
   >     ...
   >     if api_ctx.global_rules then
   >          local plugins = core.tablepool.fetch("plugins", 32, 0)
   >          local values = api_ctx.global_rules.values
   >          for _, global_rule in config_util.iterate_values(values) do
   >              core.table.clear(plugins)
   >              plugins = plugin.filter(global_rule, plugins)
   >              -- Note: here run global plugin
   >              run_plugin(phase_name, plugins, api_ctx)
   >          end
   >          core.tablepool.release("plugins", plugins)
   >      end
   >      ...
   > end
   > 
   > local function run_plugin(phase, plugins, api_ctx)
   >     .....
   >     for i = 1, #plugins, 2 do
   >          local phase_fun = plugins[i][phase]
   >          if phase_fun then
   >              phase_fun(plugins[i + 1], api_ctx)
   >          end
   >      end
   >      .....
   > end
   > -- ### cors.lua
   > function _M.header_filter(conf, ctx)
   >     .....
   >     -- Note: here the ctx is api_ctx
   >     local multiple_origin, err = core.lrucache.plugin_ctx(plugin_name, ctx,
   >                                                 create_mutiple_origin_cache, conf)
   >     .....
   > end
   > 
   > -- ### lrucache.lua
   > function _M.plugin_ctx(plugin_name, api_ctx, create_obj_fun, ...)
   >     -- Note: here used api_ctx.conf_id is nil
   >     local key = api_ctx.conf_type .. "#" .. api_ctx.conf_id
   >     return _plugin(plugin_name, key, api_ctx.conf_version, create_obj_fun, ...)
   > end
   > ```
   > 
   > ### What's the actual result? (including assertion message & call stack if applicable)
   > 2020/09/09 11:37:14 [error] 9701#9701: _373 failed to run header_filter_by_lua_: ...user-center//deps/share/lua/5.1/apisix/core/lrucache.lua:202: attempt to concaten ate field 'conf_id' (a nil value)
   > 2297217 stack traceback:
   > 2297218 ...user-center//deps/share/lua/5.1/apisix/core/lrucache.lua:202: in function 'plugin_ctx'
   > 2297219 ...-user-center//deps/share/lua/5.1/apisix/plugins/cors.lua:144: in function 'phase_fun'
   > 2297220 ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:142: in function 'run_plugin'
   > 2297221 ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:562: in function 'common_phase'
   > 2297222 ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:573: in function 'http_header_filter_phase'
   > 2297223 header_filter_by_lua:2: in main chunk, client: 172.30.212.206, server: , request: "GET /dfy-h5-user HTTP/1.0", host: "m.dafangya.com.cn"
   > 
   > ### What's the expected result?
   > 404 page.


----------------------------------------------------------------
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.

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



[GitHub] [apisix] backnero commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
backnero commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-669764548


   Thanks @membphis for your help and dedication!
   I used apisix-docker's dockerfile (centos) as a blueprint to build a version 1.5 docker image.
   
   I configured the following in the global routing rules:
   PUT text.com/apisix/admin/global_rules/1
   ```
   {
           "plugins": {
               "limit-count": {
                   "time_window": 60,
                   "policy": "local",
                   "count": 100,
                   "key": "http_x_real_ip",
                   "rejected_code": 503
               },
               "cors":{}
           }
   }
   ```
   Access to all routes has the following error in error.log
   ```
   2020/08/06 15:15:13 [error] 49#49: *56762 failed to run header_filter_by_lua*: /usr/local/apisix/apisix/core/lrucache.lua:198: attempt to concatenate field 'conf_id' (a nil value)
   stack traceback:
           /usr/local/apisix/apisix/core/lrucache.lua:198: in function 'plugin_ctx'
           /usr/local/apisix/apisix/plugins/cors.lua:144: in function 'phase_fun'
           /usr/local/apisix/apisix/init.lua:142: in function 'run_plugin'
           /usr/local/apisix/apisix/init.lua:550: in function 'common_phase'
           /usr/local/apisix/apisix/init.lua:561: in function 'http_header_filter_phase'
   ```
   After @membphis instructed, I closed the global cors configuration. The interface is currently accessible, and other errors are found.
   
   
   **Currently, I need the function of the cors plug-in while I am using it. How can I solve this problem?**


----------------------------------------------------------------
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.

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



[GitHub] [apisix] griffenliu edited a comment on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
griffenliu edited a comment on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-690836227


   I have the same problem, see #2194.
   
   > ### Issue description
   > when route not found and `return core.response.exit(404, {error_msg = "failed to match any routes"})`, the apisix throw an error.
   > 
   > ### Environment
   > * apisix version (cmd: `apisix version`): 1.5
   > * OS: Ubuntu 18.04
   > 
   > ### Minimal test code / Steps to reproduce the issue
   > 1. add global plugin cors
   > 
   > ```
   > curl -X PUT \
   >   https://{apisix_listen_address}/apisix/admin/global_rules/1 \
   >   -H 'Content-Type: application/json' \
   >   -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
   >   -d '{
   >         "plugins": {
   >             "cors": { }
   >         }
   >     }'
   > ```
   > 
   > 1. Access a nonexistent Route, for example: http://172.0.0.1:9080/test
   > 2. the apisix source code snippet
   > 
   > ```
   > -- ### init.lua
   > function _M.http_access_phase()
   >     .....
   >      -- load and run global rule
   >      if router.global_rules and router.global_rules.values
   >         and #router.global_rules.values > 0 then
   >          local plugins = core.tablepool.fetch("plugins", 32, 0)
   >          local values = router.global_rules.values
   >          for _, global_rule in config_util.iterate_values(values) do
   >              api_ctx.conf_type = "global_rule"
   >              api_ctx.conf_version = global_rule.modifiedIndex
   >              api_ctx.conf_id = global_rule.value.id
   >              core.table.clear(plugins)
   >              api_ctx.plugins = plugin.filter(global_rule, plugins)
   >              run_plugin("rewrite", plugins, api_ctx)
   >              run_plugin("access", plugins, api_ctx)
   >          end
   > 
   >          core.tablepool.release("plugins", plugins)
   >         **--  Note: api_ctx is cleared here
   >          api_ctx.plugins = nil
   >          api_ctx.conf_type = nil
   >          api_ctx.conf_version = nil
   >          api_ctx.conf_id = nil**
   >         
   >          api_ctx.global_rules = router.global_rules
   >      end
   >      .....
   >      -- Note: here no route matched, so exit 404
   >      local route = api_ctx.matched_route
   >      if not route then
   >          return core.response.exit(404,
   >                      {error_msg = "failed to match any routes"})
   >      end
   >      ...
   > end
   > -- Continue with the following code
   >  function _M.http_header_filter_phase()
   >      common_phase("header_filter")
   >  end
   > local function common_phase(phase_name)
   >     ...
   >     if api_ctx.global_rules then
   >          local plugins = core.tablepool.fetch("plugins", 32, 0)
   >          local values = api_ctx.global_rules.values
   >          for _, global_rule in config_util.iterate_values(values) do
   >              core.table.clear(plugins)
   >              plugins = plugin.filter(global_rule, plugins)
   >              -- Note: here run global plugin
   >              run_plugin(phase_name, plugins, api_ctx)
   >          end
   >          core.tablepool.release("plugins", plugins)
   >      end
   >      ...
   > end
   > 
   > local function run_plugin(phase, plugins, api_ctx)
   >     .....
   >     for i = 1, #plugins, 2 do
   >          local phase_fun = plugins[i][phase]
   >          if phase_fun then
   >              phase_fun(plugins[i + 1], api_ctx)
   >          end
   >      end
   >      .....
   > end
   > -- ### cors.lua
   > function _M.header_filter(conf, ctx)
   >     .....
   >     -- Note: here the ctx is api_ctx
   >     local multiple_origin, err = core.lrucache.plugin_ctx(plugin_name, ctx,
   >                                                 create_mutiple_origin_cache, conf)
   >     .....
   > end
   > 
   > -- ### lrucache.lua
   > function _M.plugin_ctx(plugin_name, api_ctx, create_obj_fun, ...)
   >     -- Note: here used api_ctx.conf_id is nil
   >     local key = api_ctx.conf_type .. "#" .. api_ctx.conf_id
   >     return _plugin(plugin_name, key, api_ctx.conf_version, create_obj_fun, ...)
   > end
   > ```
   > 
   > ### What's the actual result? (including assertion message & call stack if applicable)
   > 2020/09/09 11:37:14 [error] 9701#9701: _373 failed to run header_filter_by_lua_: ...user-center//deps/share/lua/5.1/apisix/core/lrucache.lua:202: attempt to concaten ate field 'conf_id' (a nil value)
   > 2297217 stack traceback:
   > 2297218 ...user-center//deps/share/lua/5.1/apisix/core/lrucache.lua:202: in function 'plugin_ctx'
   > 2297219 ...-user-center//deps/share/lua/5.1/apisix/plugins/cors.lua:144: in function 'phase_fun'
   > 2297220 ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:142: in function 'run_plugin'
   > 2297221 ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:562: in function 'common_phase'
   > 2297222 ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:573: in function 'http_header_filter_phase'
   > 2297223 header_filter_by_lua:2: in main chunk, client: 172.30.212.206, server: , request: "GET /dfy-h5-user HTTP/1.0", host: "m.dafangya.com.cn"
   > 
   > ### What's the expected result?
   > 404 page.


----------------------------------------------------------------
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.

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



[GitHub] [apisix] ShiningRush edited a comment on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
ShiningRush edited a comment on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-670311269


   @backnero Hi, I have a try in my environment, but does not reproduce the problem, can you give more detail about the bug?


----------------------------------------------------------------
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.

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



[GitHub] [apisix] griffenliu commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
griffenliu commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-694208133


   I want to use the prometheus plug-ins.
   But when I access http://localhost:9080/apisix/prometheus/metrics by document https://github.com/apache/apisix/blob/master/doc/zh-cn/plugins/prometheus.md.
   
   I got the following error to:
   ```
   2020/09/17 20:45:31 [error] 3087#3087: *11669858 failed to run header_filter_by_lua*: ...user-center//deps/share/lua/5.1/apisix/core/lrucache.lua:202: attempt to concatenate
    field 'conf_id' (a nil value)                                                                                                                                               
   stack traceback:                                                                                                                                                             
           ...user-center//deps/share/lua/5.1/apisix/core/lrucache.lua:202: in function 'plugin_ctx'                                                                            
           ...-user-center//deps/share/lua/5.1/apisix/plugins/cors.lua:144: in function 'phase_fun'                                                                             
           ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:142: in function 'run_plugin'
           ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:550: in function 'common_phase'
           ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:561: in function 'http_header_filter_phase'
           header_filter_by_lua:2: in main chunk, client: 172.30.213.200, server: , request: "GET /apisix/prometheus/metrics HTTP/1.1", host: "172.30.212.70:9080"
   ```
   
   


----------------------------------------------------------------
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.

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



[GitHub] [apisix] ShiningRush commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
ShiningRush commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-670311269


   @backnero Hi, I have a try in my environment, but does not produce the problem, can you give more detail about the bug?


----------------------------------------------------------------
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.

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



[GitHub] [apisix] dickens7 commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
dickens7 commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-756699567


   What is the meaning of this code
   
   > https://github.com/apache/apisix/blob/master/apisix/init.lua#L365-L368
   
   ```lua
   365        api_ctx.plugins = nil
   366        api_ctx.conf_type = nil
   367        api_ctx.conf_version = nil
   368        api_ctx.conf_id = nil
   ```
   
   - apisix 2.1
   ```
   2021/01/08 10:58:50 [error] 79#79: *440247 failed to run header_filter_by_lua*: /usr/local/apisix/apisix/core/lrucache.lua:162: invalid value (nil) at index 1 in table for 'concat'
   stack traceback:
           [C]: in function 'concat'
           /usr/local/apisix/apisix/core/lrucache.lua:162: in function 'plugin_ctx'
           /usr/local/apisix/apisix/plugins/cors.lua:168: in function 'phase_func'
           /usr/local/apisix/apisix/init.lua:160: in function 'run_plugin'
           /usr/local/apisix/apisix/init.lua:615: in function 'common_phase'
           /usr/local/apisix/apisix/init.lua:652: in function 'http_header_filter_phase'
   ```


----------------------------------------------------------------
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.

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



[GitHub] [apisix] backnero commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
backnero commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-669773814


   Yes, I try to configure the cors plug-in on Service and Route, not in the global, it can be used normally


----------------------------------------------------------------
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.

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



[GitHub] [apisix] ShiningRush commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
ShiningRush commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-669769777


   I found that it is because of global header_filter does not generate `conf_id`, in https://github.com/apache/apisix/blob/master/apisix/init.lua#L555
   ```
       if api_ctx.global_rules then
           local plugins = core.tablepool.fetch("plugins", 32, 0)
           local values = api_ctx.global_rules.values
           for _, global_rule in config_util.iterate_values(values) do
               // here should generate global rule's id and type like L312
               core.table.clear(plugins)
               plugins = plugin.filter(global_rule, plugins)
               run_plugin(phase_name, plugins, api_ctx)
           end
   ```
   
   I will fix it tonight.


----------------------------------------------------------------
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.

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



[GitHub] [apisix] membphis commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
membphis commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-669758323


   the user enabled `cors` plugin in global rules. this maybe useful.
   
   ![image](https://user-images.githubusercontent.com/6814606/89503656-6cc68700-d7f9-11ea-870a-d9d6a1504d88.png)
   


----------------------------------------------------------------
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.

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



[GitHub] [apisix] ShiningRush commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
ShiningRush commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-669772817


   As a workaround, you can using CORS plugin append to each route instead of global rules util the bug is resolved. @backnero 


----------------------------------------------------------------
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.

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



[GitHub] [apisix] membphis closed issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
membphis closed issue #2006:
URL: https://github.com/apache/apisix/issues/2006


   


----------------------------------------------------------------
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.

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



[GitHub] [apisix] backnero commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
backnero commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-730142547


   I had the same problem in version 2.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.

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



[GitHub] [apisix] backnero edited a comment on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
backnero edited a comment on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-669764548


   Thanks @membphis for your help and dedication!
   I used apisix-docker's dockerfile (centos) as a blueprint to build a version 1.5 docker image.
   
   I configured the following in the global routing rules:
   PUT text.com/apisix/admin/global_rules/1
   ```
   {
           "plugins": {
               "limit-count": {
                   "time_window": 60,
                   "policy": "local",
                   "count": 100,
                   "key": "http_x_real_ip",
                   "rejected_code": 503
               },
               "cors":{}
           }
   }
   ```
   Access to all routes has the following error in error.log
   ```
   2020/08/06 15:15:13 [error] 49#49: *56762 failed to run header_filter_by_lua*: /usr/local/apisix/apisix/core/lrucache.lua:198: attempt to concatenate field 'conf_id' (a nil value)
   stack traceback:
           /usr/local/apisix/apisix/core/lrucache.lua:198: in function 'plugin_ctx'
           /usr/local/apisix/apisix/plugins/cors.lua:144: in function 'phase_fun'
           /usr/local/apisix/apisix/init.lua:142: in function 'run_plugin'
           /usr/local/apisix/apisix/init.lua:550: in function 'common_phase'
           /usr/local/apisix/apisix/init.lua:561: in function 'http_header_filter_phase'
   ```
   After @membphis instructed, I closed the global cors configuration. The interface is currently accessible, and no other errors
   
   
   
   **Currently, I need the function of the cors plug-in while I am using it. How can I solve this problem?**


----------------------------------------------------------------
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.

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



[GitHub] [apisix] griffenliu commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
griffenliu commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-690836227


   I have the same problem, see #2194.
   
   > ### Issue description
   > when route not found and `return core.response.exit(404, {error_msg = "failed to match any routes"})`, the apisix occur error.
   > 
   > ### Environment
   > * apisix version (cmd: `apisix version`): 1.5
   > * OS: Ubuntu 18.04
   > 
   > ### Minimal test code / Steps to reproduce the issue
   > 1. add global plugin cors
   > 
   > ```
   > curl -X PUT \
   >   https://{apisix_listen_address}/apisix/admin/global_rules/1 \
   >   -H 'Content-Type: application/json' \
   >   -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
   >   -d '{
   >         "plugins": {
   >             "cors": { }
   >         }
   >     }'
   > ```
   > 
   > 1. Access a nonexistent Route, for example: http://172.0.0.1:9080/test
   > 2. the apisix source code snippet
   > 
   > ```
   > -- ### init.lua
   > function _M.http_access_phase()
   >     .....
   >      -- load and run global rule
   >      if router.global_rules and router.global_rules.values
   >         and #router.global_rules.values > 0 then
   >          local plugins = core.tablepool.fetch("plugins", 32, 0)
   >          local values = router.global_rules.values
   >          for _, global_rule in config_util.iterate_values(values) do
   >              api_ctx.conf_type = "global_rule"
   >              api_ctx.conf_version = global_rule.modifiedIndex
   >              api_ctx.conf_id = global_rule.value.id
   >              core.table.clear(plugins)
   >              api_ctx.plugins = plugin.filter(global_rule, plugins)
   >              run_plugin("rewrite", plugins, api_ctx)
   >              run_plugin("access", plugins, api_ctx)
   >          end
   > 
   >          core.tablepool.release("plugins", plugins)
   >         **--  Note: api_ctx is cleared here
   >          api_ctx.plugins = nil
   >          api_ctx.conf_type = nil
   >          api_ctx.conf_version = nil
   >          api_ctx.conf_id = nil**
   >         
   >          api_ctx.global_rules = router.global_rules
   >      end
   >      .....
   >      -- Note: here no route matched, so exit 404
   >      local route = api_ctx.matched_route
   >      if not route then
   >          return core.response.exit(404,
   >                      {error_msg = "failed to match any routes"})
   >      end
   >      ...
   > end
   > -- Continue with the following code
   >  function _M.http_header_filter_phase()
   >      common_phase("header_filter")
   >  end
   > local function common_phase(phase_name)
   >     ...
   >     if api_ctx.global_rules then
   >          local plugins = core.tablepool.fetch("plugins", 32, 0)
   >          local values = api_ctx.global_rules.values
   >          for _, global_rule in config_util.iterate_values(values) do
   >              core.table.clear(plugins)
   >              plugins = plugin.filter(global_rule, plugins)
   >              -- Note: here run global plugin
   >              run_plugin(phase_name, plugins, api_ctx)
   >          end
   >          core.tablepool.release("plugins", plugins)
   >      end
   >      ...
   > end
   > 
   > local function run_plugin(phase, plugins, api_ctx)
   >     .....
   >     for i = 1, #plugins, 2 do
   >          local phase_fun = plugins[i][phase]
   >          if phase_fun then
   >              phase_fun(plugins[i + 1], api_ctx)
   >          end
   >      end
   >      .....
   > end
   > -- ### cors.lua
   > function _M.header_filter(conf, ctx)
   >     .....
   >     -- Note: here the ctx is api_ctx
   >     local multiple_origin, err = core.lrucache.plugin_ctx(plugin_name, ctx,
   >                                                 create_mutiple_origin_cache, conf)
   >     .....
   > end
   > 
   > -- ### lrucache.lua
   > function _M.plugin_ctx(plugin_name, api_ctx, create_obj_fun, ...)
   >     -- Note: here used api_ctx.conf_id is nil
   >     local key = api_ctx.conf_type .. "#" .. api_ctx.conf_id
   >     return _plugin(plugin_name, key, api_ctx.conf_version, create_obj_fun, ...)
   > end
   > ```
   > 
   > ### What's the actual result? (including assertion message & call stack if applicable)
   > 2020/09/09 11:37:14 [error] 9701#9701: _373 failed to run header_filter_by_lua_: ...user-center//deps/share/lua/5.1/apisix/core/lrucache.lua:202: attempt to concaten ate field 'conf_id' (a nil value)
   > 2297217 stack traceback:
   > 2297218 ...user-center//deps/share/lua/5.1/apisix/core/lrucache.lua:202: in function 'plugin_ctx'
   > 2297219 ...-user-center//deps/share/lua/5.1/apisix/plugins/cors.lua:144: in function 'phase_fun'
   > 2297220 ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:142: in function 'run_plugin'
   > 2297221 ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:562: in function 'common_phase'
   > 2297222 ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:573: in function 'http_header_filter_phase'
   > 2297223 header_filter_by_lua:2: in main chunk, client: 172.30.212.206, server: , request: "GET /dfy-h5-user HTTP/1.0", host: "m.dafangya.com.cn"
   > 
   > ### What's the expected result?
   > 404 page.


----------------------------------------------------------------
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.

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



[GitHub] [apisix] dickens7 commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
dickens7 commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-759957902


   upgrade to `2.2` the problem remains unresolved
   
   Steps to reproduce
   
   1.  add global_rules
   ```
   curl -X PUT \
     http://127.0.0.1:9080/apisix/admin/global_rules/1 \
     -H 'Content-Type: application/json' \
     -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
     -d '{"plugins": {"cors": {}}}'
   ```
   
   2. add my service route
   ```
   $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
   {
       "uri": "/*",
       "upstream": {
           "type": "roundrobin",
           "nodes": {
               "127.0.0.1:8999": 1
           }
       }
   }'
   ```
   3. my service open status
   
   >  curl http://127.0.0.1:9080/
   
   - response
   ```
   Hello world
   ```
   
   4. my service close status
   
   > curl http://127.0.0.1:9080/
   
   - response
   
   ```
   <html>
   <head><title>502 Bad Gateway</title></head>
   <body>
   <center><h1>502 Bad Gateway</h1></center>
   <hr><center>openresty</center>
   </body>
   </html>
   ```
   - error log
   ```
   2021/01/14 06:27:24 [error] 36#36: *53399 failed to run header_filter_by_lua*: /usr/local/apisix/apisix/core/lrucache.lua:159: invalid value (nil) at index 1 in table for 'concat'
   stack traceback:
           [C]: in function 'concat'
           /usr/local/apisix/apisix/core/lrucache.lua:159: in function 'plugin_ctx'
           /usr/local/apisix/apisix/plugins/cors.lua:168: in function 'phase_func'
           /usr/local/apisix/apisix/init.lua:164: in function 'run_plugin'
           /usr/local/apisix/apisix/init.lua:625: in function 'common_phase'
           /usr/local/apisix/apisix/init.lua:662: in function 'http_header_filter_phase'
           header_filter_by_lua:2: in main chunk, client: 10.42.1.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1:9080"
   ```
   


----------------------------------------------------------------
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.

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



[GitHub] [apisix] griffenliu commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
griffenliu commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-690836227


   I have the same problem, see #2194.
   
   > ### Issue description
   > when route not found and `return core.response.exit(404, {error_msg = "failed to match any routes"})`, the apisix occur error.
   > 
   > ### Environment
   > * apisix version (cmd: `apisix version`): 1.5
   > * OS: Ubuntu 18.04
   > 
   > ### Minimal test code / Steps to reproduce the issue
   > 1. add global plugin cors
   > 
   > ```
   > curl -X PUT \
   >   https://{apisix_listen_address}/apisix/admin/global_rules/1 \
   >   -H 'Content-Type: application/json' \
   >   -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
   >   -d '{
   >         "plugins": {
   >             "cors": { }
   >         }
   >     }'
   > ```
   > 
   > 1. Access a nonexistent Route, for example: http://172.0.0.1:9080/test
   > 2. the apisix source code snippet
   > 
   > ```
   > -- ### init.lua
   > function _M.http_access_phase()
   >     .....
   >      -- load and run global rule
   >      if router.global_rules and router.global_rules.values
   >         and #router.global_rules.values > 0 then
   >          local plugins = core.tablepool.fetch("plugins", 32, 0)
   >          local values = router.global_rules.values
   >          for _, global_rule in config_util.iterate_values(values) do
   >              api_ctx.conf_type = "global_rule"
   >              api_ctx.conf_version = global_rule.modifiedIndex
   >              api_ctx.conf_id = global_rule.value.id
   >              core.table.clear(plugins)
   >              api_ctx.plugins = plugin.filter(global_rule, plugins)
   >              run_plugin("rewrite", plugins, api_ctx)
   >              run_plugin("access", plugins, api_ctx)
   >          end
   > 
   >          core.tablepool.release("plugins", plugins)
   >         **--  Note: api_ctx is cleared here
   >          api_ctx.plugins = nil
   >          api_ctx.conf_type = nil
   >          api_ctx.conf_version = nil
   >          api_ctx.conf_id = nil**
   >         
   >          api_ctx.global_rules = router.global_rules
   >      end
   >      .....
   >      -- Note: here no route matched, so exit 404
   >      local route = api_ctx.matched_route
   >      if not route then
   >          return core.response.exit(404,
   >                      {error_msg = "failed to match any routes"})
   >      end
   >      ...
   > end
   > -- Continue with the following code
   >  function _M.http_header_filter_phase()
   >      common_phase("header_filter")
   >  end
   > local function common_phase(phase_name)
   >     ...
   >     if api_ctx.global_rules then
   >          local plugins = core.tablepool.fetch("plugins", 32, 0)
   >          local values = api_ctx.global_rules.values
   >          for _, global_rule in config_util.iterate_values(values) do
   >              core.table.clear(plugins)
   >              plugins = plugin.filter(global_rule, plugins)
   >              -- Note: here run global plugin
   >              run_plugin(phase_name, plugins, api_ctx)
   >          end
   >          core.tablepool.release("plugins", plugins)
   >      end
   >      ...
   > end
   > 
   > local function run_plugin(phase, plugins, api_ctx)
   >     .....
   >     for i = 1, #plugins, 2 do
   >          local phase_fun = plugins[i][phase]
   >          if phase_fun then
   >              phase_fun(plugins[i + 1], api_ctx)
   >          end
   >      end
   >      .....
   > end
   > -- ### cors.lua
   > function _M.header_filter(conf, ctx)
   >     .....
   >     -- Note: here the ctx is api_ctx
   >     local multiple_origin, err = core.lrucache.plugin_ctx(plugin_name, ctx,
   >                                                 create_mutiple_origin_cache, conf)
   >     .....
   > end
   > 
   > -- ### lrucache.lua
   > function _M.plugin_ctx(plugin_name, api_ctx, create_obj_fun, ...)
   >     -- Note: here used api_ctx.conf_id is nil
   >     local key = api_ctx.conf_type .. "#" .. api_ctx.conf_id
   >     return _plugin(plugin_name, key, api_ctx.conf_version, create_obj_fun, ...)
   > end
   > ```
   > 
   > ### What's the actual result? (including assertion message & call stack if applicable)
   > 2020/09/09 11:37:14 [error] 9701#9701: _373 failed to run header_filter_by_lua_: ...user-center//deps/share/lua/5.1/apisix/core/lrucache.lua:202: attempt to concaten ate field 'conf_id' (a nil value)
   > 2297217 stack traceback:
   > 2297218 ...user-center//deps/share/lua/5.1/apisix/core/lrucache.lua:202: in function 'plugin_ctx'
   > 2297219 ...-user-center//deps/share/lua/5.1/apisix/plugins/cors.lua:144: in function 'phase_fun'
   > 2297220 ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:142: in function 'run_plugin'
   > 2297221 ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:562: in function 'common_phase'
   > 2297222 ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:573: in function 'http_header_filter_phase'
   > 2297223 header_filter_by_lua:2: in main chunk, client: 172.30.212.206, server: , request: "GET /dfy-h5-user HTTP/1.0", host: "m.dafangya.com.cn"
   > 
   > ### What's the expected result?
   > 404 page.


----------------------------------------------------------------
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.

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



[GitHub] [apisix] backnero commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
backnero commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-670334062


   
   Okay, I added the SSL configuration (for example: xxx.com), and added the route of xxx.com/v1/xxx. When I set to enable cors globally, this error will appear. At this time, the root path and routing are not accessible. Turn off the global cors plugin and configure only the cors plugin of xxx.com/v1/xxx, the root path and routing can be accessed。
   
   The same configuration is usually used in version 1.4.1, which is normal. But in version 1.5, need to turn off the global cors plugin and enable cors for specific services or routes


----------------------------------------------------------------
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.

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



[GitHub] [apisix] griffenliu edited a comment on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
griffenliu edited a comment on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-694208133


   I want to use the prometheus plug-ins.
   But when I access http://localhost:9080/apisix/prometheus/metrics based on the document https://github.com/apache/apisix/blob/master/doc/zh-cn/plugins/prometheus.md.
   
   I got the following error too:
   ```
   2020/09/17 20:45:31 [error] 3087#3087: *11669858 failed to run header_filter_by_lua*: ...user-center//deps/share/lua/5.1/apisix/core/lrucache.lua:202: attempt to concatenate
    field 'conf_id' (a nil value)                                                                                                                                               
   stack traceback:                                                                                                                                                             
           ...user-center//deps/share/lua/5.1/apisix/core/lrucache.lua:202: in function 'plugin_ctx'                                                                            
           ...-user-center//deps/share/lua/5.1/apisix/plugins/cors.lua:144: in function 'phase_fun'                                                                             
           ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:142: in function 'run_plugin'
           ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:550: in function 'common_phase'
           ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:561: in function 'http_header_filter_phase'
           header_filter_by_lua:2: in main chunk, client: 172.30.213.200, server: , request: "GET /apisix/prometheus/metrics HTTP/1.1", host: "172.30.212.70:9080"
   ```
   
   


----------------------------------------------------------------
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.

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



[GitHub] [apisix] membphis commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
membphis commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-669758531


   @ShiningRush do you have time to handle this bug?


----------------------------------------------------------------
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.

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



[GitHub] [apisix] moonming commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
moonming commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-694633467


   @membphis please take a look


----------------------------------------------------------------
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.

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



[GitHub] [apisix] dickens7 removed a comment on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
dickens7 removed a comment on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-759957902


   upgrade to `2.2` the problem remains unresolved
   
   Steps to reproduce
   
   1.  add global_rules
   ```
   curl -X PUT \
     http://127.0.0.1:9080/apisix/admin/global_rules/1 \
     -H 'Content-Type: application/json' \
     -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
     -d '{"plugins": {"cors": {}}}'
   ```
   
   2. add my service route
   ```
   $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
   {
       "uri": "/*",
       "upstream": {
           "type": "roundrobin",
           "nodes": {
               "127.0.0.1:8999": 1
           }
       }
   }'
   ```
   3. my service open status
   
   >  curl http://127.0.0.1:9080/
   
   - response
   ```
   Hello world
   ```
   
   4. my service close status
   
   > curl http://127.0.0.1:9080/
   
   - response
   
   ```
   <html>
   <head><title>502 Bad Gateway</title></head>
   <body>
   <center><h1>502 Bad Gateway</h1></center>
   <hr><center>openresty</center>
   </body>
   </html>
   ```
   - error log
   ```
   2021/01/14 06:27:24 [error] 36#36: *53399 failed to run header_filter_by_lua*: /usr/local/apisix/apisix/core/lrucache.lua:159: invalid value (nil) at index 1 in table for 'concat'
   stack traceback:
           [C]: in function 'concat'
           /usr/local/apisix/apisix/core/lrucache.lua:159: in function 'plugin_ctx'
           /usr/local/apisix/apisix/plugins/cors.lua:168: in function 'phase_func'
           /usr/local/apisix/apisix/init.lua:164: in function 'run_plugin'
           /usr/local/apisix/apisix/init.lua:625: in function 'common_phase'
           /usr/local/apisix/apisix/init.lua:662: in function 'http_header_filter_phase'
           header_filter_by_lua:2: in main chunk, client: 10.42.1.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1:9080"
   ```
   


----------------------------------------------------------------
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.

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



[GitHub] [apisix] membphis commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
membphis commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-757695002


   @dickens7 what version are you using? the latest version of APISIX is `2.2`, we may have fixed this issue.
   
   if you still have this issue, please create a new issue and report your APISIX version.


----------------------------------------------------------------
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.

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



[GitHub] [apisix] griffenliu commented on issue #2006: bug(cors): attempt to concatenate field 'conf_id' (a nil value)

Posted by GitBox <gi...@apache.org>.
griffenliu commented on issue #2006:
URL: https://github.com/apache/apisix/issues/2006#issuecomment-690836227


   I have the same problem, see #2194.
   
   > ### Issue description
   > when route not found and `return core.response.exit(404, {error_msg = "failed to match any routes"})`, the apisix occur error.
   > 
   > ### Environment
   > * apisix version (cmd: `apisix version`): 1.5
   > * OS: Ubuntu 18.04
   > 
   > ### Minimal test code / Steps to reproduce the issue
   > 1. add global plugin cors
   > 
   > ```
   > curl -X PUT \
   >   https://{apisix_listen_address}/apisix/admin/global_rules/1 \
   >   -H 'Content-Type: application/json' \
   >   -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
   >   -d '{
   >         "plugins": {
   >             "cors": { }
   >         }
   >     }'
   > ```
   > 
   > 1. Access a nonexistent Route, for example: http://172.0.0.1:9080/test
   > 2. the apisix source code snippet
   > 
   > ```
   > -- ### init.lua
   > function _M.http_access_phase()
   >     .....
   >      -- load and run global rule
   >      if router.global_rules and router.global_rules.values
   >         and #router.global_rules.values > 0 then
   >          local plugins = core.tablepool.fetch("plugins", 32, 0)
   >          local values = router.global_rules.values
   >          for _, global_rule in config_util.iterate_values(values) do
   >              api_ctx.conf_type = "global_rule"
   >              api_ctx.conf_version = global_rule.modifiedIndex
   >              api_ctx.conf_id = global_rule.value.id
   >              core.table.clear(plugins)
   >              api_ctx.plugins = plugin.filter(global_rule, plugins)
   >              run_plugin("rewrite", plugins, api_ctx)
   >              run_plugin("access", plugins, api_ctx)
   >          end
   > 
   >          core.tablepool.release("plugins", plugins)
   >         **--  Note: api_ctx is cleared here
   >          api_ctx.plugins = nil
   >          api_ctx.conf_type = nil
   >          api_ctx.conf_version = nil
   >          api_ctx.conf_id = nil**
   >         
   >          api_ctx.global_rules = router.global_rules
   >      end
   >      .....
   >      -- Note: here no route matched, so exit 404
   >      local route = api_ctx.matched_route
   >      if not route then
   >          return core.response.exit(404,
   >                      {error_msg = "failed to match any routes"})
   >      end
   >      ...
   > end
   > -- Continue with the following code
   >  function _M.http_header_filter_phase()
   >      common_phase("header_filter")
   >  end
   > local function common_phase(phase_name)
   >     ...
   >     if api_ctx.global_rules then
   >          local plugins = core.tablepool.fetch("plugins", 32, 0)
   >          local values = api_ctx.global_rules.values
   >          for _, global_rule in config_util.iterate_values(values) do
   >              core.table.clear(plugins)
   >              plugins = plugin.filter(global_rule, plugins)
   >              -- Note: here run global plugin
   >              run_plugin(phase_name, plugins, api_ctx)
   >          end
   >          core.tablepool.release("plugins", plugins)
   >      end
   >      ...
   > end
   > 
   > local function run_plugin(phase, plugins, api_ctx)
   >     .....
   >     for i = 1, #plugins, 2 do
   >          local phase_fun = plugins[i][phase]
   >          if phase_fun then
   >              phase_fun(plugins[i + 1], api_ctx)
   >          end
   >      end
   >      .....
   > end
   > -- ### cors.lua
   > function _M.header_filter(conf, ctx)
   >     .....
   >     -- Note: here the ctx is api_ctx
   >     local multiple_origin, err = core.lrucache.plugin_ctx(plugin_name, ctx,
   >                                                 create_mutiple_origin_cache, conf)
   >     .....
   > end
   > 
   > -- ### lrucache.lua
   > function _M.plugin_ctx(plugin_name, api_ctx, create_obj_fun, ...)
   >     -- Note: here used api_ctx.conf_id is nil
   >     local key = api_ctx.conf_type .. "#" .. api_ctx.conf_id
   >     return _plugin(plugin_name, key, api_ctx.conf_version, create_obj_fun, ...)
   > end
   > ```
   > 
   > ### What's the actual result? (including assertion message & call stack if applicable)
   > 2020/09/09 11:37:14 [error] 9701#9701: _373 failed to run header_filter_by_lua_: ...user-center//deps/share/lua/5.1/apisix/core/lrucache.lua:202: attempt to concaten ate field 'conf_id' (a nil value)
   > 2297217 stack traceback:
   > 2297218 ...user-center//deps/share/lua/5.1/apisix/core/lrucache.lua:202: in function 'plugin_ctx'
   > 2297219 ...-user-center//deps/share/lua/5.1/apisix/plugins/cors.lua:144: in function 'phase_fun'
   > 2297220 ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:142: in function 'run_plugin'
   > 2297221 ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:562: in function 'common_phase'
   > 2297222 ...odes/dfy-user-center//deps/share/lua/5.1/apisix/init.lua:573: in function 'http_header_filter_phase'
   > 2297223 header_filter_by_lua:2: in main chunk, client: 172.30.212.206, server: , request: "GET /dfy-h5-user HTTP/1.0", host: "m.dafangya.com.cn"
   > 
   > ### What's the expected result?
   > 404 page.


----------------------------------------------------------------
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.

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