Skip to content

Commit 5347d39

Browse files
committed
Fix invalid output when upstream re-resolved
1 parent c382342 commit 5347d39

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
@@ -633,6 +633,55 @@ ngx_http_vhost_traffic_status_display_set_upstream_group(ngx_http_request_t *r,
633633

634634
zone = 1;
635635

636+
#if nginx_version > 1027003
637+
for (peers = uscf->peer.data; peers; peers = peers->next) {
638+
ngx_http_upstream_rr_peers_rlock(peers);
639+
for (peer = peers->peer; peer; peer = peer->next) {
640+
p = ngx_cpymem(p, uscf->host.data, uscf->host.len);
641+
*p++ = NGX_HTTP_VHOST_TRAFFIC_STATUS_KEY_SEPARATOR;
642+
p = ngx_cpymem(p, peer->name.data, peer->name.len);
643+
644+
dst.len = uscf->host.len + sizeof("@") - 1 + peer->name.len;
645+
646+
rc = ngx_http_vhost_traffic_status_node_generate_key(r->pool, &key, &dst, type);
647+
if (rc != NGX_OK) {
648+
ngx_http_upstream_rr_peers_unlock(peers);
649+
return buf;
650+
}
651+
652+
hash = ngx_crc32_short(key.data, key.len);
653+
node = ngx_http_vhost_traffic_status_node_lookup(ctx->rbtree, &key, hash);
654+
655+
usn.weight = peer->weight;
656+
usn.max_fails = peer->max_fails;
657+
usn.fail_timeout = peer->fail_timeout;
658+
usn.backup = 0;
659+
#if (NGX_HTTP_UPSTREAM_CHECK)
660+
if (ngx_http_upstream_check_peer_down(peer->check_index)) {
661+
usn.down = 1;
662+
663+
} else {
664+
usn.down = 0;
665+
}
666+
#else
667+
usn.down = (peer->fails >= peer->max_fails || peer->down);
668+
#endif
669+
670+
usn.name = peer->name;
671+
672+
if (node != NULL) {
673+
vtsn = (ngx_http_vhost_traffic_status_node_t *) &node->color;
674+
buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, vtsn);
675+
} else {
676+
buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, NULL);
677+
}
678+
p = dst.data;
679+
}
680+
ngx_http_upstream_rr_peers_unlock(peers);
681+
}
682+
goto last;
683+
#endif
684+
636685
peers = uscf->peer.data;
637686

638687
ngx_http_upstream_rr_peers_rlock(peers);
@@ -744,6 +793,7 @@ ngx_http_vhost_traffic_status_display_set_upstream_group(ngx_http_request_t *r,
744793
}
745794
}
746795

796+
last:
747797
if (s == buf) {
748798
buf = o;
749799

0 commit comments

Comments
 (0)