bug: Enable http-logger plugin in the route will cause an error log
Issue description
Enable http-logger plugin in the route will cause an error log.
Environment
- apisix version (cmd:
apisix version): master - OS:
Minimal test code / Steps to reproduce the issue
- set the route
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"plugins": {
"http-logger": {
"uri": "127.0.0.1:9797/postendpoint?param=1"
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:9797": 1
}
},
"uri": "/test"
}'
- request the route
curl 127.0.0.1:9080/test
3.
$ cat error.log
2020/11/11 16:45:09 [error] 41367#2352668: *2007998 lua entry thread aborted: runtime error: /Users/idbeta/1106/apisix/apisix/plugins/http-logger.lua:103: bad argument #1 to 'connect' (string expected, got nil)
stack traceback:
coroutine 0:
[C]: in function 'connect'
/Users/idbeta/1106/apisix/apisix/plugins/http-logger.lua:103: in function 'func'
/Users/idbeta/1106/apisix/apisix/utils/batch-processor.lua:59: in function </Users/idbeta/1106/apisix/apisix/utils/batch-processor.lua:54>, context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:9080
You should use http://127.0.0.1:9797/postendpoint?param=1. BTW, we need to verify the input.
@spacewander https://github.com/apache/apisix/blob/master/doc/plugins/http-logger.md the documentation is 127.0.0.1:9797/postendpoint?param=1, and the problem still exists even I used http://127.0.0.1:9797/postendpoint?param=1
@idbeta
I tried http://127.0.0.1:9797/postendpoint?param=1 but it works well for me:
incubator-apisix (doc_disp*) 0
¥ curl 127.0.0.1:9080/test
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>openresty</center>
</body>
</html>
incubator-apisix (doc_disp*) 0
¥ tail -f logs/error.log
2020/11/11 17:00:50 [warn] 88683#88683: *12 [lua] plugin.lua:178: load_stream(): new plugins: {"mqtt-proxy":true}, context: init_worker_by_lua*
2020/11/11 17:00:50 [warn] 88678#88678: *11 [lua] plugin.lua:178: load_stream(): new plugins: {"mqtt-proxy":true}, context: init_worker_by_lua*
2020/11/11 17:00:50 [warn] 88675#88675: *3 [lua] plugin.lua:178: load_stream(): new plugins: {"mqtt-proxy":true}, context: init_worker_by_lua*
2020/11/11 17:00:50 [warn] 88682#88682: *10 [lua] plugin.lua:178: load_stream(): new plugins: {"mqtt-proxy":true}, context: init_worker_by_lua*
2020/11/11 17:00:50 [warn] 88687#88687: *13 [lua] plugin.lua:130: load(): new plugins: {"redirect":true,"uri-blocker":true,"fault-injection":true,"proxy-mirror":true,"serverless-post-function":true,"zipkin":true,"batch-requests":true,"request-validation":true,"limit-count":true,"openid-connect":true,"prometheus":true,"limit-conn":true,"ip-restriction":true,"wolf-rbac":true,"basic-auth":true,"key-auth":true,"limit-req":true,"api-breaker":true,"hmac-auth":true,"request-id":true,"proxy-cache":true,"consumer-restriction":true,"tcp-logger":true,"cors":true,"referer-restriction":true,"echo":true,"proxy-rewrite":true,"grpc-transcode":true,"http-logger":true,"serverless-pre-function":true,"response-rewrite":true,"node-status":true,"authz-keycloak":true,"kafka-logger":true,"jwt-auth":true,"syslog":true,"udp-logger":true}, context: init_worker_by_lua*
2020/11/11 17:00:50 [warn] 88673#88673: *160 [lua] init.lua:262: sync_local_conf_to_etcd(): sync local conf to etcd, context: ngx.timer
2020/11/11 17:00:50 [warn] 88677#88677: *5 [lua] plugin.lua:178: load_stream(): new plugins: {"mqtt-proxy":true}, context: init_worker_by_lua*
2020/11/11 17:00:50 [warn] 88680#88680: *7 [lua] plugin.lua:178: load_stream(): new plugins: {"mqtt-proxy":true}, context: init_worker_by_lua*
2020/11/11 17:00:50 [warn] 88687#88687: *13 [lua] plugin.lua:178: load_stream(): new plugins: {"mqtt-proxy":true}, context: init_worker_by_lua*
2020/11/11 17:01:55 [error] 88674#88674: *12041 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: , request: "GET /test HTTP/1.1", upstream: "http://127.0.0.1:9797/test", host: "127.0.0.1:9080"
^C
The cause of the problem has been found, it is my environment problem, not the plug-in problem.
127.0.0.1:9797/postendpoint?param=1 also can work for me now.