Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx still use the down peer #66

Open
ensonz opened this issue Oct 12, 2018 · 1 comment
Open

nginx still use the down peer #66

ensonz opened this issue Oct 12, 2018 · 1 comment

Comments

@ensonz
Copy link

ensonz commented Oct 12, 2018

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;
}
@ygm521
Copy link

ygm521 commented Aug 4, 2022

did you sloved it thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants