Skip to content

Commit

Permalink
fix down status on dns sync
Browse files Browse the repository at this point in the history
  • Loading branch information
ZigzagAK committed Oct 12, 2018
1 parent 2572160 commit 2917f1e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
27 changes: 19 additions & 8 deletions src/ngx_dynamic_upstream_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ static const ngx_str_t ngx_dynamic_upstream_params[] = {
ngx_string("arg_verbose"),
ngx_string("arg_add"),
ngx_string("arg_remove"),
ngx_string("arg_sync"),
ngx_string("arg_backup"),
ngx_string("arg_server"),
ngx_string("arg_weight"),
Expand Down Expand Up @@ -674,7 +673,7 @@ ngx_dynamic_upstream_op_servers(PeersT *primary,
peer->server.len);
server->name.len = peer->server.len;
server->backup = peers == primary->next;
server->down = peer->down;
server->down = peer->down != 0;
server->weight = peer->weight;
server->max_fails = peer->max_fails;
server->fail_timeout = peer->fail_timeout;
Expand Down Expand Up @@ -767,12 +766,22 @@ ngx_dynamic_upstream_op_sync(ngx_log_t *log,
#endif
op->fail_timeout = server[j].fail_timeout;

if (server[j].down
|| (op->op_param & NGX_DYNAMIC_UPSTEAM_OP_PARAM_DOWN)) {
if (op->op_param & NGX_DYNAMIC_UPSTEAM_OP_PARAM_UP) {

op->op_param &= ~NGX_DYNAMIC_UPSTEAM_OP_PARAM_DOWN;
op->down = 0;
} else if (op->op_param & NGX_DYNAMIC_UPSTEAM_OP_PARAM_DOWN) {

op->op_param &= ~NGX_DYNAMIC_UPSTEAM_OP_PARAM_UP;
op->down = 1;
}

if (!server[j].resolve && server[j].down) {

op->op_param &= ~NGX_DYNAMIC_UPSTEAM_OP_PARAM_UP;
op->op_param |= NGX_DYNAMIC_UPSTEAM_OP_PARAM_DOWN;
op->down = 1;
} else
op->op_param &= ~NGX_DYNAMIC_UPSTEAM_OP_PARAM_DOWN;
}

if (ngx_dynamic_upstream_op_add_peer<PeersT, PeerT>
(log, op, shpool, primary, &server[j].u, i) == NGX_ERROR)
Expand Down Expand Up @@ -888,8 +897,10 @@ ngx_dynamic_cleanup(ngx_event_t *ev)

settimer:

if (!ngx_exiting)
ngx_add_timer(ev, 1000);
if (ngx_exiting || ngx_terminate || ngx_quit)
return;

ngx_add_timer(ev, 1000);
}


Expand Down
3 changes: 2 additions & 1 deletion src/ngx_http_dynamic_upstream_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,8 @@ ngx_dynamic_upstream_loop()
if (ucscf->add_down != NGX_CONF_UNSET && ucscf->add_down) {
op.op_param |= NGX_DYNAMIC_UPSTEAM_OP_PARAM_DOWN;
op.down = 1;
}
} else
op.op_param |= NGX_DYNAMIC_UPSTEAM_OP_PARAM_UP;

ngx_dynamic_upstream_loop_conf_cb(uscf[j], &conf, &op);

Expand Down
6 changes: 3 additions & 3 deletions t/03-add.t
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ server 127.0.0.1:6004 addr=127.0.0.1:6004;
}
--- request
GET /dynamic?upstream=backends&server=127.0.0.1:6004&add=&weight=10
--- response_body
--- response_body_like
server 127.0.0.1:6001 addr=127.0.0.1:6001 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0;
server 127.0.0.1:6002 addr=127.0.0.1:6002 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0;
server 127.0.0.1:6003 addr=127.0.0.1:6003 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0;
Expand Down Expand Up @@ -99,7 +99,7 @@ server 127.0.0.1:6004 addr=127.0.0.1:6004 weight=10 max_fails=1 fail_timeout=10
}
--- request
GET /dynamic?upstream=backends&server=127.0.0.1:6004&add=&backup=
--- response_body
--- response_body_like
server 127.0.0.1:6001 addr=127.0.0.1:6001;
server 127.0.0.1:6002 addr=127.0.0.1:6002;
server 127.0.0.1:6003 addr=127.0.0.1:6003;
Expand Down Expand Up @@ -157,7 +157,7 @@ server 127.0.0.1:6004 addr=127.0.0.1:6004 backup;
}
--- request
GET /test
--- response_body
--- response_body_like
DNS resolving in progress
server 127.0.0.1:6001 addr=127.0.0.1:6001;
server 127.0.0.1:6002 addr=127.0.0.1:6002;
Expand Down
8 changes: 4 additions & 4 deletions t/03-stream-add.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ __DATA__
}
--- request
GET /dynamic?upstream=backends&server=127.0.0.1:6004&add=&stream=
--- response_body
--- response_body_like
server 127.0.0.1:6001 addr=127.0.0.1:6001;
server 127.0.0.1:6002 addr=127.0.0.1:6002;
server 127.0.0.1:6003 addr=127.0.0.1:6003;
Expand All @@ -47,7 +47,7 @@ server 127.0.0.1:6004 addr=127.0.0.1:6004;
}
--- request
GET /dynamic?upstream=backends&server=127.0.0.1:6004&add=&weight=10&stream=
--- response_body
--- response_body_like
server 127.0.0.1:6001 addr=127.0.0.1:6001 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0;
server 127.0.0.1:6002 addr=127.0.0.1:6002 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0;
server 127.0.0.1:6003 addr=127.0.0.1:6003 weight=1 max_fails=1 fail_timeout=10 max_conns=0 conns=0;
Expand Down Expand Up @@ -110,7 +110,7 @@ server 127.0.0.1:6004 addr=127.0.0.1:6004 weight=10 max_fails=1 fail_timeout=10
}
--- request
GET /dynamic?upstream=backends&server=127.0.0.1:6004&add=&backup=&stream=
--- response_body
--- response_body_like
server 127.0.0.1:6001 addr=127.0.0.1:6001;
server 127.0.0.1:6002 addr=127.0.0.1:6002;
server 127.0.0.1:6003 addr=127.0.0.1:6003;
Expand Down Expand Up @@ -172,7 +172,7 @@ server 127.0.0.1:6004 addr=127.0.0.1:6004 backup;
}
--- request
GET /test
--- response_body
--- response_body_like
DNS resolving in progress
server 127.0.0.1:6001 addr=127.0.0.1:6001;
server 127.0.0.1:6002 addr=127.0.0.1:6002;
Expand Down

0 comments on commit 2917f1e

Please sign in to comment.