Skip to content

Commit 1881fdb

Browse files
committed
Fix invalid output when upstream re-resolved
1 parent ea759b6 commit 1881fdb

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/ngx_http_vhost_traffic_status_display_json.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,55 @@ ngx_http_vhost_traffic_status_display_set_upstream_group(ngx_http_request_t *r,
607607

608608
zone = 1;
609609

610+
#if nginx_version > 1027003
611+
for (peers = uscf->peer.data; peers; peers = peers->next) {
612+
ngx_http_upstream_rr_peers_rlock(peers);
613+
for (peer = peers->peer; peer; peer = peer->next) {
614+
p = ngx_cpymem(p, uscf->host.data, uscf->host.len);
615+
*p++ = NGX_HTTP_VHOST_TRAFFIC_STATUS_KEY_SEPARATOR;
616+
p = ngx_cpymem(p, peer->name.data, peer->name.len);
617+
618+
dst.len = uscf->host.len + sizeof("@") - 1 + peer->name.len;
619+
620+
rc = ngx_http_vhost_traffic_status_node_generate_key(r->pool, &key, &dst, type);
621+
if (rc != NGX_OK) {
622+
ngx_http_upstream_rr_peers_unlock(peers);
623+
return buf;
624+
}
625+
626+
hash = ngx_crc32_short(key.data, key.len);
627+
node = ngx_http_vhost_traffic_status_node_lookup(ctx->rbtree, &key, hash);
628+
629+
usn.weight = peer->weight;
630+
usn.max_fails = peer->max_fails;
631+
usn.fail_timeout = peer->fail_timeout;
632+
usn.backup = 0;
633+
#if (NGX_HTTP_UPSTREAM_CHECK)
634+
if (ngx_http_upstream_check_peer_down(peer->check_index)) {
635+
usn.down = 1;
636+
637+
} else {
638+
usn.down = 0;
639+
}
640+
#else
641+
usn.down = (peer->fails >= peer->max_fails || peer->down);
642+
#endif
643+
644+
usn.name = peer->name;
645+
646+
if (node != NULL) {
647+
vtsn = (ngx_http_vhost_traffic_status_node_t *) &node->color;
648+
buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, vtsn);
649+
} else {
650+
buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, NULL);
651+
}
652+
p = dst.data;
653+
}
654+
ngx_http_upstream_rr_peers_unlock(peers);
655+
}
656+
goto last;
657+
#endif
658+
610659
peers = uscf->peer.data;
611660

612661
ngx_http_upstream_rr_peers_rlock(peers);
@@ -718,6 +767,7 @@ ngx_http_vhost_traffic_status_display_set_upstream_group(ngx_http_request_t *r,
718767
}
719768
}
720769

770+
last:
721771
if (s == buf) {
722772
buf = o;
723773

0 commit comments

Comments
 (0)