bug: enabled active health checks, error.log has extra content.
Issue description
I had foo.com when I set health check first time, and then I set it again and remove foo.com, but the log will still record foo.com.
first time:
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/404.html",
"upstream": {
"nodes": {
"45.76.29.156:80": 1,
"127.0.0.1:9797": 1
},
"type": "roundrobin",
"retries": 2,
"checks": {
"active": {
"timeout": 5,
"http_path": "/404.html",
"host": "foo.com",
"healthy": {
"interval": 2,
"successes": 1
},
"unhealthy": {
"interval": 1,
"http_failures": 2
},
"req_headers": ["User-Agent: curl/7.29.0"]
}
}
}
}'
second time
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/404.html",
"upstream": {
"nodes": {
"45.76.29.156:80": 1,
"127.0.0.1:9797": 1
},
"type": "roundrobin",
"retries": 2,
"checks": {
"active": {
"timeout": 5,
"http_path": "/404.html",
"healthy": {
"interval": 2,
"successes": 1
},
"unhealthy": {
"interval": 1,
"http_failures": 2
},
"req_headers": ["User-Agent: curl/7.29.0"]
}
}
}
}'
the error.log
2020/11/14 11:46:54 [warn] 95077#3298494: *1652550 [lua] healthcheck.lua:1107: log():
[healthcheck] (upstream#/apisix/routes/1) unhealthy HTTP increment (1/2) for 'foo.com(45.76.29.156:80)',
context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:9080
2020/11/14 11:46:54 [warn] 95077#3298494: *1652550 [lua] healthcheck.lua:1107: log():
[healthcheck] (upstream#/apisix/routes/1) unhealthy HTTP increment (2/2) for '(45.76.29.156:80)',
context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:9080
2020/11/14 11:46:55 [warn] 95077#3298494: *1652680 [lua] healthcheck.lua:1107: log():
[healthcheck] (upstream#/apisix/routes/1) healthy SUCCESS increment (1/1) for '(45.76.29.156:80)',
context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:9080
2020/11/14 11:46:55 [warn] 95077#3298494: *1652695 [lua] healthcheck.lua:1107: log():
[healthcheck] (upstream#/apisix/routes/1) healthy SUCCESS increment (1/1) for 'foo.com(45.76.29.156:80)',
context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:9080
Environment
- apisix version (cmd:
apisix version): master - OS:
Where is 'foo.com' come from?
Where is 'foo.com' come from?
I updated my description, it should be clearer now
Even I set different nodes in the second time, the health check will still check the old node set last time. But the etcd data records is new already.
Here is my steps, I got the same wrong result, so I think this issue is a bug:
# set route with healthcheck(host is foo.com)
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/hello",
"upstream": {
"nodes": {
"127.0.0.1:1980": 1,
"127.0.0.2:1981": 1
},
"type": "roundrobin",
"checks": {
"active": {
"timeout": 5,
"http_path": "/404.html",
"host": "foo.com",
"healthy": {
"interval": 1,
"successes": 2
},
"unhealthy": {
"interval": 1,
"http_failures": 2
}
}
}
}
}'
# call the API
curl http://127.0.0.1:9080/hello
# set a new route with healthcheck(host: xxxx.com)
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/hello",
"upstream": {
"nodes": {
"127.0.0.1:1980": 1,
"127.0.0.2:1981": 1
},
"type": "roundrobin",
"retries": 2,
"checks": {
"active": {
"timeout": 5,
"http_path": "/404.html",
"host": "xxxx.com",
"healthy": {
"interval": 1,
"successes": 2
},
"unhealthy": {
"interval": 1,
"http_failures": 2
}
}
}
}
}'
# call the API again
curl http://127.0.0.1:9080/hello
# then shutdown the upstream server, check the error log
kill your-upstream-pid
At the end, we can get the error log:

Needs to call the checker:clear() before we call the stop method.
Here is the bugfix patch, welcome PR:
diff --git a/apisix/balancer.lua b/apisix/balancer.lua
index 4eba0bbd..a9c0f3dc 100644
--- a/apisix/balancer.lua
+++ b/apisix/balancer.lua
@@ -106,6 +106,7 @@ local function create_checker(upstream, healthcheck_parent)
if upstream.parent then
core.table.insert(upstream.parent.clean_handlers, function ()
core.log.info("try to release checker: ", tostring(checker))
+ checker:clear()
checker:stop()
end)
it is not easy to write the test cases. I think we can check this case in E2E(shell script).
Thanks for the hint, I will try to fix it.