gxthrj opened a new issue #878: bug: 插件热更新,导致业务请求出错
URL: https://github.com/apache/incubator-apisix/issues/878
 
 
   ### Issue description
   1、写一个access阶段的插件,让其运行时出错
   ```
   if not conf.origins or conf.origins[1] == "*" then -- conf.origins 可能为nil
   ...
   end
   ```
   访问业务请求
   ```
   ➜ curl -XOPTIONS http://172.16.20.90:32537/hello
   <html>
   <head><title>502 Bad Gateway</title></head>
   <body>
   <center><h1>502 Bad Gateway</h1></center>
   <hr><center>openresty</center>
   </body>
   </html>
   ```
   报错信息如下
   ```
   2019/11/19 14:02:43 [error] 47#47: *241608 failed to run 
header_filter_by_lua*: /usr/local/apisix/lua/apisix/plugins/xxx.lua:36: attempt 
to index field 'origins' (a nil value)
   stack traceback:
        /usr/local/apisix/lua/apisix/plugins/xxx.lua:36: in function 'origin'
        /usr/local/apisix/lua/apisix/plugins/xxx.lua:88: in function 'phase_fun'
        /usr/local/apisix/lua/apisix.lua:129: in function 'run_plugin'
        /usr/local/apisix/lua/apisix.lua:400: in function 
'http_header_filter_phase'
        header_filter_by_lua:2: in main chunk while reading response header 
from upstream, client: 10.244.0.0, server: , request: "OPTIONS /hello 
HTTP/1.1", upstream: "http://10.244.1.8:8080/hello";, host: "172.16.20.90:32537"
   ```
   2、修改插件,加上nil判断
   ```
   if not conf.origins or conf.origins[1] == "*" then
   ...
   end
   ```
   3、插件reload
   ```
   curl http://127.0.0.1:9080/apisix/admin/plugins/reload -X PUT
   ```
   4、访问数次业务请求,偶现502
   ```
   ➜ curl -XOPTIONS http://172.16.20.90:32537/hello
   hello, world! v6%                                                            
                        
   ➜ curl -XOPTIONS http://172.16.20.90:32537/hello
   hello, world! v6%                                                            
                        
   ➜ curl -XOPTIONS http://172.16.20.90:32537/hello
   hello, world! v6%                                                            
                        
   ➜ curl -XOPTIONS http://172.16.20.90:32537/hello
   <html>
   <head><title>502 Bad Gateway</title></head>
   <body>
   <center><h1>502 Bad Gateway</h1></center>
   <hr><center>openresty</center>
   </body>
   </html>
   ➜ curl -XOPTIONS http://172.16.20.90:32537/hello
   hello, world! v6%                                                            
                        
   ➜ curl -XOPTIONS http://172.16.20.90:32537/hello
   hello, world! v6%                                                            
                        
   ➜ curl -XOPTIONS http://172.16.20.90:32537/hello
   hello, world! v6%                                                            
                        
   ➜ curl -XOPTIONS http://172.16.20.90:32537/hello
   hello, world! v6%                                                            
                        
   ➜ curl -XOPTIONS http://172.16.20.90:32537/hello
   ^[[A<html>
   <head><title>502 Bad Gateway</title></head>
   <body>
   <center><h1>502 Bad Gateway</h1></center>
   <hr><center>openresty</center>
   </body>
   </html>
   ```
   5、对应的error.log
   ```
   2019/11/19 14:08:38 [error] 47#47: *251963 connect() failed (113: No route 
to host) while connecting to upstream, client: 10.244.0.0, server: , request: 
"OPTIONS /hello HTTP/1.1", upstream: "http://10.244.1.2:8080/hello";, host: 
"172.16.20.90:32537"
   2019/11/19 14:09:10 [error] 48#48: *252928 connect() failed (113: No route 
to host) while connecting to upstream, client: 10.244.0.0, server: , request: 
"OPTIONS /hello HTTP/1.1", upstream: "http://10.244.1.2:8080/hello";, host: 
"172.16.20.90:32537"
   ```
   
   ### Environment
   
   * apisix version (cmd: `apisix version`): 0.8
   * OS: docker centos
   
   
   

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to