griffenliu opened a new issue #1667:
URL: https://github.com/apache/apisix/issues/1667


   ### Issue description
   I customized a plug-in for global rules,When I set the configuration 
enable_debug=true, i got the follow error:
   ```
   2020/06/08 11:40:56 [error] 15825#0: *330 failed to run body_filter_by_lua*: 
/usr/local/share/lua/5.1/apisix/plugin.lua:260: headers have already been sent
   stack traceback:
           [C]: in function 'error'
           /usr/local/share/lua/5.1/apisix/core/response.lua:90: in function 
'set_header'
           /usr/local/share/lua/5.1/apisix/plugin.lua:260: in function 'filter'
           /usr/local/share/lua/5.1/apisix/init.lua:456: in function 
'common_phase'
           /usr/local/share/lua/5.1/apisix/init.lua:470: in function 
'http_body_filter_phase'
           body_filter_by_lua:2: in main chunk, client: ::1, server: , request: 
"GET /config HTTP/1.1", host: "localhost:9080"
   
   ```
   
   ### Environment
   
   * apisix version (cmd: `apisix version`): 1.2
   * OS: Ubuntu 18.04
   
   ### Minimal test code / Steps to reproduce the issue
   1. config.yaml
   ```
   apisix:
        enable_debug: true
   
   plugins:
       - my_custom_plugin
   ```
   2. my_custom_plugin.lua
   ```
   local core = require("apisix.core")
   
   local plugin_name = "my_custom_plugin"
   local schema = {}
   
   local _M = {
       version = 0.1,
       priority = 0,
       name = plugin_name,
       schema = schema,
   }
   
   function _M.access(conf, ctx)
   --    core.response.exit(200, "测试!!!")
   --    return 200, "测试!!!"
   end
   return _M
   ```
   3. set global rule:
   ```
   curl -X PUT \
     http://localhost:9080/apisix/admin/global_rules/1 \
     -H 'Content-Type: application/json' \
     -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
     -d '{
           "plugins": {
               "my_custom_plugin": {}
           }
       }'
   
   ```
   
   ### What's the actual result? (including assertion message & call stack if 
applicable)
   ```
   ➜  ~ curl http://localhost:9080/config
   curl: (52) Empty reply from server
   ```
   
   ### What's the expected result?
   ➜  ~ curl http://localhost:9080/config
   {"error_msg":"failed to match any 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:
[email protected]


Reply via email to