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

   ### Current Behavior
   
   When I access the route with curl, it returns a 500 error
   ```shell
   curl -H "Content-Type: application/json" \
   --data '{"jsonrpc":"2.0","method":"cccc","params":[],"id":83}' \
   http://127.0.0.1/test-send-raw-split
   ``` 
   ```html
   <!DOCTYPE html>
   <html>
   <head>
   <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
   <meta content="utf-8" http-equiv="encoding">
   <title>500 Internal Server Error</title>
   <style>
       body {
           width: 35em;
           margin: 0 auto;
           font-family: Tahoma, Verdana, Arial, sans-serif;
       }
   </style>
   </head>
   <body>
   <h1>An error occurred.</h1>
   <p>You can report issue to <a 
href="https://github.com/apache/apisix/issues";>APISIX</a></p>
   <p><em>Faithfully yours, <a 
href="https://apisix.apache.org/";>APISIX</a>.</em></p>
   </body>
   </html>
   ``` 
   
   ### Expected Behavior
   
   It should proxy to echo-api.3scale.net normally and return the request 
information
   
   ### Error Logs
   
   ```
   2023/07/18 03:48:31 [error] 1282#1282: *17141381 lua entry thread aborted: 
runtime error: /usr/local/openresty/lualib/resty/lrucache.lua:227: table index 
is nil
   stack traceback:
   coroutine 0:
        /usr/local/openresty/lualib/resty/lrucache.lua: in function 'set'
        /usr/local/apisix/apisix/core/lrucache.lua:97: in function 
'cached_validator'
        /usr/local/apisix/apisix/core/schema.lua:49: in function 'get_validator'
        /usr/local/apisix/apisix/core/schema.lua:60: in function 'check'
        [string "local core = require('apisix.core');..."]:41: in function 
'getter'
        /usr/local/apisix/apisix/core/ctx.lua:287: in function '__index'
        /usr/local/apisix//deps/share/lua/5.1/resty/expr/v1.lua:291: in 
function 'eval'
        /usr/local/apisix/apisix/plugins/traffic-split.lua:249: in function 
'phase_func'
        /usr/local/apisix/apisix/plugin.lua:934: in function 'run_plugin'
        /usr/local/apisix/apisix/init.lua:506: in function 'http_access_phase'
        access_by_lua(nginx.conf:479):2: in main chunk, client: 127.0.0.1, 
server: _, request: "POST /test-send-raw-split HTTP/1.1", host: "127.0.0.1"
   127.0.0.1 - - [18/Jul/2023:03:48:31 +0000] http://127.0.0.1 "POST 
/test-send-raw-split HTTP/1.1" 500 565 0.002 "-" "curl/7.58.0" - - - 
"http://127.0.0.1";
   ``` 
   
   ### Steps to Reproduce
   
   1.Run Apisix 2.15.3 in docker.
   2.Config a route like this.
   ```yaml
   uri: /test-send-raw-split
   name: test-send-raw-split
   plugins:
     serverless-pre-function:
       functions:
         - |
           local core = require('apisix.core');
           local conf = {
             check_result = 'ok',
             body_schema = {
               properties = {
                 method = {
                   pattern = '^(?!aaa|bbb)',
                   type = 'string'
                 }
               },
               required = {'method'},
               type = 'object'
             }
           }
   
           return function(conf, ctx)
             core.ctx.register_var("check_result", function(ctx)
               local req_body
               local body, err = core.request.get_body()
               if not body then
                 if err then
                   core.log.error("failed to get body: ", err)
                 end
                 conf.check_result = "no"
               end
   
               local headers = core.request.headers(ctx)
               if headers["content-type"] == 
"application/x-www-form-urlencoded" then
                 -- use 0 to avoid truncated result and keep the behavior as the
                 -- same as other platforms
                 req_body, err = ngx.decode_args(body, 0)
               else -- JSON as default
                 req_body, err = core.json.decode(body)
               end
   
               if not req_body then
                 core.log.error('failed to decode the req body: ', err)
                 conf.check_result = "no"
               end
   
               local ok, err = core.schema.check(conf.body_schema, req_body)
               if not ok then
                 core.log.error("req schema validation failed: ", err)
                 conf.check_result = "no"
               end
   
               return conf.check_result
             end)
           end
       phase: rewrite
     traffic-split:
       rules:
         - match:
             - vars:
                 - - check_result
                   - '=='
                   - ok
           weighted_upstreams:
             - upstream:
                 nodes:
                   echo-api.3scale.net: 1
                 type: roundrobin
         - match:
             - vars:
                 - - check_result
                   - '=='
                   - 'no'
           weighted_upstreams:
             - upstream:
                 nodes:
                   echo-api.3scale.net: 1
                 type: roundrobin
   status: 1
   
   ``` 
   3.Use the curl command to request a configured route.
   ```shell
   curl -H "Content-Type: application/json" --data 
'{"jsonrpc":"2.0","method":"cccc","params":[],"id":83}' 
http://127.0.0.1/test-send-raw-split
   ``` 
   
   ### Environment
   
   - APISIX version (run `apisix version`):2.15.3
   - Operating system (run `uname -a`):Linux k8s-m-2 4.19.225-0419225-generic 
#202201110859 SMP Tue Jan 11 14:15:40 UTC 2022 x86_64 GNU/Linux
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`):nginx 
version: openresty/1.21.4.1
   built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
   built with OpenSSL 1.1.1s  1 Nov 2022
   TLS SNI support enabled
   configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt='-O2 
-DAPISIX_BASE_VER=1.21.4.1.7 
-DNGX_GRPC_CLI_ENGINE_PATH=/usr/local/openresty/libgrpc_engine.so 
-DNGX_HTTP_GRPC_CLI_ENGINE_PATH=/usr/local/openresty/libgrpc_engine.so 
-DNGX_LUA_ABORT_AT_PANIC -I/usr/local/openresty/zlib/include 
-I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl111/include' 
--add-module=../ngx_devel_kit-0.3.1 --add-module=../echo-nginx-module-0.62 
--add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 
--add-module=../set-misc-nginx-module-0.33 
--add-module=../form-input-nginx-module-0.12 
--add-module=../encrypted-session-nginx-module-0.09 
--add-module=../srcache-nginx-module-0.32 --add-module=../ngx_lua-0.10.21 
--add-module=../ngx_lua_upstream-0.07 
--add-module=../headers-more-nginx-module-0.33 
--add-module=../array-var-nginx-module-0.05 
--add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 
--add-module=../redis-nginx-module-0.3.9 --ad
 d-module=../ngx_stream_lua-0.0.11 
--with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib 
-Wl,-rpath,/usr/local/openresty/wasmtime-c-api/lib 
-L/usr/local/openresty/zlib/lib -L/usr/local/openresty/pcre/lib 
-L/usr/local/openresty/openssl111/lib 
-Wl,-rpath,/usr/local/openresty/zlib/lib:/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl111/lib'
 --add-module=/tmp/tmp.XAafuZTCsa/openresty-1.21.4.1/../mod_dubbo-1.0.2 
--add-module=/tmp/tmp.XAafuZTCsa/openresty-1.21.4.1/../ngx_multi_upstream_module-1.1.1
 
--add-module=/tmp/tmp.XAafuZTCsa/openresty-1.21.4.1/../apisix-nginx-module-1.12.0
 
--add-module=/tmp/tmp.XAafuZTCsa/openresty-1.21.4.1/../apisix-nginx-module-1.12.0/src/stream
 
--add-module=/tmp/tmp.XAafuZTCsa/openresty-1.21.4.1/../apisix-nginx-module-1.12.0/src/meta
 --add-module=/tmp/tmp.XAafuZTCsa/openresty-1.21.4.1/../wasm-nginx-module-0.6.4 
--add-module=/tmp/tmp.XAafuZTCsa/openresty-1.21.4.1/../lua-var-nginx-module-v0.5.3
 --add-module=/tmp/tmp.XAafuZTCsa/openresty-1.21.4.1/../grp
 c-client-nginx-module-v0.4.2 --with-poll_module --with-pcre-jit --with-stream 
--with-stream_ssl_module --with-stream_ssl_preread_module --with-http_v2_module 
--without-mail_pop3_module --without-mail_imap_module 
--without-mail_smtp_module --with-http_stub_status_module 
--with-http_realip_module --with-http_addition_module 
--with-http_auth_request_module --with-http_secure_link_module 
--with-http_random_index_module --with-http_gzip_static_module 
--with-http_sub_module --with-http_dav_module --with-http_flv_module 
--with-http_mp4_module --with-http_gunzip_module --with-threads --with-compat 
--with-stream --with-http_ssl_module
   - 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`):
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to