openresty / openresty/lua-upstream-nginx-module
nginx still use the down peer
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 512
- Forks
- 153
- Avg merge
- 1h 29m
- Merged PRs (30d)
- 2
Description
I use ngx.upstream.get_primary_peers and find a peer is down。But nginx still use the bad peer。
log:
2018/10/12 16:14:36 [debug] 1998#1998: *508497 [lua] test.lua:21: gen_peers_status_info(): name:123.157.76.2:80stat: up
2018/10/12 16:14:36 [debug] 1998#1998: *508497 [lua] test.lua:21: gen_peers_status_info(): name:123.157.76.5:80stat: DOWN
2018/10/12 16:14:36 [debug] 1998#1998: *508497 [lua] test.lua:21: gen_peers_status_info(): name:60.217.244.95:80stat: up
2018/10/12 16:14:36 [debug] 1998#1998: *508497 http cleanup add: 0000000003439608
2018/10/12 16:14:36 [debug] 1998#1998: *508497 http script var: "/a64/0/ads11euyc1dsa0pb.dsaudio"
2018/10/12 16:14:36 [debug] 1998#1998: *508497 consistent hash [peer name]:123.157.76.5:80 4170160978
2018/10/12 16:14:36 [debug] 1998#1998: *508497 stream socket 18
lua file:
local u = "test.domain.com"
local ok, upstream = pcall(require, "ngx.upstream")
if not ok then
error("ngx_upstream_lua module required")
end
local set_peer_down = upstream.set_peer_down
local get_primary_peers = upstream.get_primary_peers
local get_backup_peers = upstream.get_backup_peers
local get_upstreams = upstream.get_upstreams
local function gen_peers_status_info(peers)
local npeers = #peers
for i = 1, npeers do
local peer = peers[i]
local stat = ""
if peer.down then
stat = " DOWN\n"
else
stat = " up\n"
end
ngx.log(ngx.DEBUG,"name:",peer.name,"stat:",stat)
end
return idx
end
local peers, err = get_primary_peers(u)
if not peers then
return "failed to get primary peers in upstream " .. u .. ": "
.. err
end
gen_peers_status_info(peers)
peers, err = get_backup_peers(u)
if not peers then
return "failed to get backup peers in upstream " .. u .. ": "
.. err
end
gen_peers_status_info(peers)
upstream config :
upstream test.domain.com {
consistent_hash $uri;
#server 123.157.76.2:80 id=1001 weight=1 max_fails=2 fail_timeout=30s;
#server 123.157.76.5:80 id=1002 weight=1 max_fails=2 fail_timeout=30s;
server 123.157.76.2:80;
server 123.157.76.5:80;
server 60.217.244.95:80 backup;
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported selection with the Lua code in test.lua and the supplied test.domain.com upstream configuration. Trace the get_primary_peers result through the consistent-hash request path, then determine whether the down peer should be excluded and add a regression test if the relevant test location is found. Done means the reported down peer is no longer selected, or the issue is explained as expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, lua
- Domain
- backend, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100