When run test cases in my local environment, it usually occur some error(error log pasted blow).
I check the code, found it cause by that cls-sdk parsing hostname failure.
I can't stably reproduce this bug. So, my idea is just handle this error to avoid nil pointer expection. (But, it seems hard to add corresponding test cases, if you have good idea, please give me some suggestions.)
FLUSH_ETCD=1 prove -I. -I../test-nginx/inc -I../test-nginx/lib -r t/plugin/ua-restriction.t
t/plugin/ua-restriction.t .. 129/?
# Failed test 't/plugin/ua-restriction.t TEST 33: the element in allowlist is null - pattern "[error]" should not match any line in error.log but matches line "2023/07/15 22:59:07 [error] 32850\#31262134: *2 [lua] plugin.lua:135: load_plugin(): failed to load plugin [tencent-cloud-cls] err: ...ects/apisix/apisix/plugins/tencent-cloud-cls/cls-sdk.lua:65: bad argument \#1 to 'ipairs' (table expected, got nil), context: init_worker_by_lua*" (req 0)
# 2023/07/15 22:59:07 [notice] 32850\#31262134: *2 [lua] config_etcd.lua:980: new(): use loaded configuration /protos, context: init_worker_by_lua*
# 2023/07/15 22:59:07 [notice] 32849\#31262133: *1 [lua] config_etcd.lua:980: new(): use loaded configuration /protos, context: init_worker_by_lua*
# 2023/07/15 22:59:07 [info] 32850\#31262134: *2 [lua] plugin.lua:239: load(): load plugin times: 1, context: init_worker_by_lua*
# 2023/07/15 22:59:07 [warn] 32850\#31262134: *2 [lua] plugin.lua:252: load_stream(): new plugins: {"syslog":true,"ip-restriction":true,"limit-conn":true,"mqtt-proxy":true}, context: init_worker_by_lua*
# 2023/07/15 22:59:07 [info] 32849\#31262133: *1 [lua] plugin.lua:239: load(): load plugin times: 1, context: init_worker_by_lua*
# 2023/07/15 22:59:07 [warn] 32849\#31262133: *1 [lua] plugin.lua:252: load_stream(): new plugins: {"syslog":true,"ip-restriction":true,"limit-conn":true,"mqtt-proxy":true}, context: init_worker_by_lua*
# 2023/07/15 22:59:07 [info] 32849\#31262133: *1 [lua] plugin.lua:280: load_stream(): stream plugins: [{"preread":"function: 0x011079c7e8","schema":{"oneOf":[{"required":["whitelist"]},{"required":["blacklist"]}],"type":"object","$comment":"this is a mark for our injected plugin schema","properties":{"whitelist":{"minItems":1,"type":"array","items":{"anyOf":[{"title":"IPv4","type":"string","format":"ipv4"},{"title":"IPv4/CIDR","type":"string","pattern":"^([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])/([12]?[0-9]|3[0-2])$"},{"title":"IPv6","type":"string","format":"ipv6"},{"title":"IPv6/CIDR","type":"string","pattern":"^([a-fA-F0-9]{0,4}:){1,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?/[0-9]{1,3}$"}]}},"blacklist":{"minItems":1,"type":"array","items":{"anyOf":"table: 0x01106c78d0"}},"_meta":{"type":"object","properties":{"priority":{"description":"priority of plugins by customized order","type":"integer"},"error_response":{"oneOf":[{"type":"string"},{"type":"object"}]},"disable":{"type":"boolean"},"filter":{"description":"filter determines whether the plugin needs to be executed at runtime","type":"array"}}},"message":{"minLength":1,"type":"string","default":"Your IP address is not allowed","maxLength":1024}}},"restrict":"function: 0x011079c7e8","priority":3000,"name":"ip-restriction","check_schema":"function: 0x011079c630","version":0.1},{"preread":"function: 0x0110ad8860","schema":{"type":"object","required":["conn","burst","default_conn_delay","key"],"$comment":"this is a mark for our injected plugin schema","properties":{"burst":{"type":"integer","minimum":0},"default_conn_delay":{"type":"number","exclusiveMinimum":0},"only_use_default_delay":{"type":"boolean","default":false},"conn":{"type":"integer","exclusiveMinimum":0},"_meta":"table: 0x0110786c40","key":{"type":"string"},"key_type":{"enum":["var","var_combination"],"type":"string","default":"var"}}},"version":0.1,"priority":1003,"log":"function: 0x0110a48d20","check_schema":"function: 0x0110c7ce58","name":"limit-conn"},{"preread":"function: 0x0110c552b0","schema":{"type":"object","required":["protocol_name","protocol_level"],"$comment":"this is a mark for our injected plugin schema","properties":{"_meta":"table: 0x0110786c40","protocol_name":{"type":"string"},"protocol_level":{"type":"integer"}}},"version":0.1,"priority":1000,"log":"function: 0x0110c5b288","check_schema":"function: 0x0110c0bab8","name":"mqtt-proxy"},{"version":0.1,"check_schema":"function: 0x0110b33a80","name":"syslog","schema":{"type":"object","required":["host","port"],"$comment":"this is a mark for our injected plugin schema","properties":{"port":{"type":"integer"},"drop_limit":{"type":"integer","default":1048576},"sock_type":{"enum":["tcp","udp"],"type":"string","default":"tcp"},"pool_size":{"minimum":5,"type":"integer","default":5},"host":{"type":"string"},"timeout":{"minimum":1,"type":"integer","default":3000},"log_format":{"type":"object"},"flush_limit":{"minimum":1,"type":"integer","default":4096},"_meta":"table: 0x0110786c40","tls":{"type":"boolean","default":false},"name":{"type":"string","default":"stream sys logger"},"retry_delay":{"minimum":0,"type":"integer","default":1},"batch_max_size":{"minimum":1,"type":"integer","default":1000},"max_retry_count":{"minimum":0,"type":"integer","default":0},"inactive_timeout":{"minimum":1,"type":"integer","default":5},"buffer_duration":{"minimum":1,"type":"integer","default":60}}},"priority":401,"log":"function: 0x0110b3ca70","metadata_schema":{"type":"object","properties":{"log_format":{"type":"object","default":{"host":"$host","@timestamp":"$time_iso8601","client_ip":"$remote_addr"}}}},"flush_syslog":"function: 0x0111135a48"}], context: init_worker_by_lua*
# 2023/07/15 22:59:07 [info] 32849\#31262133: *1 [lua] plugin.lua:282: load_stream(): load stream plugin times: 1, context: init_worker_by_lua*
# 2023/07/15 22:59:07 [notice] 32849\#31262133: *1 [lua] config_etcd.lua:980: new(): use loaded configuration /plugin_metadata, context: init_worker_by_lua*
# '
# at /Users/jiangfucheng/projects/apisix/../test-nginx/lib/Test/Nginx/Socket.pm line 1354.
# Looks like you failed 1 test of 136.
t/plugin/ua-restriction.t .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/136 subtests
nginx version: openresty/1.21.4.1
built by clang 14.0.3 (clang-1403.0.22.14.1)
built with OpenSSL 1.1.1n 15 Mar 2022
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt='-O2 -DAPISIX_BASE_VER=0.0.0 -DNGX_GRPC_CLI_ENGINE_PATH=/usr/local/openresty/libgrpc_engine.so -DNGX_HTTP_GRPC_CLI_ENGINE_PATH=/usr/local/openresty/libgrpc_engine.so -I/opt/homebrew/opt/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 --add-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/opt/homebrew/opt/openresty-openssl111/lib' --add-module=/Users/jiangfucheng/learning/openresty/build-apisix-dev/openresty-1.21.4.1/../mod_dubbo --add-module=/Users/jiangfucheng/learning/openresty/build-apisix-dev/openresty-1.21.4.1/../ngx_multi_upstream_module --add-module=/Users/jiangfucheng/learning/openresty/build-apisix-dev/openresty-1.21.4.1/../apisix-nginx-module --add-module=/Users/jiangfucheng/learning/openresty/build-apisix-dev/openresty-1.21.4.1/../apisix-nginx-module/src/stream --add-module=/Users/jiangfucheng/learning/openresty/build-apisix-dev/openresty-1.21.4.1/../apisix-nginx-module/src/meta --add-module=/Users/jiangfucheng/learning/openresty/build-apisix-dev/openresty-1.21.4.1/../wasm-nginx-module --add-module=/Users/jiangfucheng/learning/openresty/build-apisix-dev/openresty-1.21.4.1/../lua-var-nginx-module --add-module=/Users/jiangfucheng/learning/openresty/build-apisix-dev/openresty-1.21.4.1/../grpc-client-nginx-module --with-poll_module --with-pcre-jit --with-pcre=/Users/jiangfucheng/learning/openresty/build-apisix-dev/pcre-8.45 --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-pcre-opt=-g --with-stream --with-http_ssl_module
Current Behavior
When run test cases in my local environment, it usually occur some error(error log pasted blow).
I check the code, found it cause by that
cls-sdkparsinghostnamefailure.apisix/apisix/plugins/tencent-cloud-cls/cls-sdk.lua
Lines 62 to 69 in 772ebd1
I can't stably reproduce this bug. So, my idea is just handle this error to avoid
nil pointer expection. (But, it seems hard to add corresponding test cases, if you have good idea, please give me some suggestions.)Expected Behavior
No error log
Error Logs
Steps to Reproduce
1.run any unit test case, eg:
FLUSH_ETCD=1 prove -I. -I../test-nginx/inc -I../test-nginx/lib -r t/plugin/ua-restriction.tEnvironment
apisix version): 3.4.0uname -a):Darwin jiangfuchengdeMacBook-Pro.local 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000 arm64openresty -Vornginx -V):curl http://127.0.0.1:9090/v1/server_info):luarocks --version):