1diff --git a/src/http/modules/ngx_http_upstream_hash_module.c b/src/http/modules/ngx_http_upstream_hash_module.c 2index 777e180..b6b7830 100644 3--- a/src/http/modules/ngx_http_upstream_hash_module.c 4+++ b/src/http/modules/ngx_http_upstream_hash_module.c 5@@ -9,6 +9,9 @@ 6 #include <ngx_core.h> 7 #include <ngx_http.h> 8 9+#if (NGX_HTTP_UPSTREAM_CHECK) 10+#include "ngx_http_upstream_check_module.h" 11+#endif 12 13 typedef struct { 14 uint32_t hash; 15@@ -240,6 +243,15 @@ ngx_http_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data) 16 goto next; 17 } 18 19+#if (NGX_HTTP_UPSTREAM_CHECK) 20+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, 21+ "get hash peer, check_index: %ui", 22+ peer->check_index); 23+ if (ngx_http_upstream_check_peer_down(peer->check_index)) { 24+ goto next; 25+ } 26+#endif 27+ 28 if (peer->max_fails 29 && peer->fails >= peer->max_fails 30 && now - peer->checked <= peer->fail_timeout) 31@@ -506,6 +518,15 @@ ngx_http_upstream_get_chash_peer(ngx_peer_connection_t *pc, void *data) 32 continue; 33 } 34 35+#if (NGX_HTTP_UPSTREAM_CHECK) 36+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, 37+ "get consistent_hash peer, check_index: %ui", 38+ peer->check_index); 39+ if (ngx_http_upstream_check_peer_down(peer->check_index)) { 40+ continue; 41+ } 42+#endif 43+ 44 if (peer->server.len != server->len 45 || ngx_strncmp(peer->server.data, server->data, server->len) 46 != 0) 47diff --git a/src/http/modules/ngx_http_upstream_ip_hash_module.c b/src/http/modules/ngx_http_upstream_ip_hash_module.c 48index 148d73a..913e395 100644 49--- a/src/http/modules/ngx_http_upstream_ip_hash_module.c 50+++ b/src/http/modules/ngx_http_upstream_ip_hash_module.c 51@@ -9,6 +9,9 @@ 52 #include <ngx_core.h> 53 #include <ngx_http.h> 54 55+#if (NGX_HTTP_UPSTREAM_CHECK) 56+#include "ngx_http_upstream_check_module.h" 57+#endif 58 59 typedef struct { 60 /* the round robin data must be first */ 61@@ -212,6 +215,15 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data) 62 goto next_try; 63 } 64 65+#if (NGX_HTTP_UPSTREAM_CHECK) 66+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, 67+ "get ip_hash peer, check_index: %ui", 68+ peer->check_index); 69+ if (ngx_http_upstream_check_peer_down(peer->check_index)) { 70+ goto next_try; 71+ } 72+#endif 73+ 74 if (peer->max_fails 75 && peer->fails >= peer->max_fails 76 && now - peer->checked <= peer->fail_timeout) 77diff --git a/src/http/modules/ngx_http_upstream_least_conn_module.c b/src/http/modules/ngx_http_upstream_least_conn_module.c 78index 623bc9b..a223839 100644 79--- a/src/http/modules/ngx_http_upstream_least_conn_module.c 80+++ b/src/http/modules/ngx_http_upstream_least_conn_module.c 81@@ -9,6 +9,9 @@ 82 #include <ngx_core.h> 83 #include <ngx_http.h> 84 85+#if (NGX_HTTP_UPSTREAM_CHECK) 86+#include "ngx_http_upstream_check_module.h" 87+#endif 88 89 typedef struct { 90 ngx_uint_t *conns; 91@@ -203,6 +206,16 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data) 92 continue; 93 } 94 95+#if (NGX_HTTP_UPSTREAM_CHECK) 96+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, 97+ "get least_conn peer, check_index: %ui", 98+ peer->check_index); 99+ 100+ if (ngx_http_upstream_check_peer_down(peer->check_index)) { 101+ continue; 102+ } 103+#endif 104+ 105 if (peer->max_fails 106 && peer->fails >= peer->max_fails 107 && now - peer->checked <= peer->fail_timeout) 108@@ -256,6 +269,16 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data) 109 continue; 110 } 111 112+#if (NGX_HTTP_UPSTREAM_CHECK) 113+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, 114+ "get least_conn peer, check_index: %ui", 115+ peer->check_index); 116+ 117+ if (ngx_http_upstream_check_peer_down(peer->check_index)) { 118+ continue; 119+ } 120+#endif 121+ 122 if (lcp->conns[i] * best->weight != lcp->conns[p] * peer->weight) { 123 continue; 124 } 125diff --git a/src/http/ngx_http_upstream_round_robin.c b/src/http/ngx_http_upstream_round_robin.c 126index 2d0649b..b9789eb 100644 127--- a/src/http/ngx_http_upstream_round_robin.c 128+++ b/src/http/ngx_http_upstream_round_robin.c 129@@ -9,6 +9,9 @@ 130 #include <ngx_core.h> 131 #include <ngx_http.h> 132 133+#if (NGX_HTTP_UPSTREAM_CHECK) 134+#include "ngx_http_upstream_check_module.h" 135+#endif 136 137 #define ngx_http_upstream_tries(p) ((p)->number \ 138 + ((p)->next ? (p)->next->number : 0)) 139@@ -92,6 +95,14 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf, 140 peer[n].fail_timeout = server[i].fail_timeout; 141 peer[n].down = server[i].down; 142 peer[n].server = server[i].name; 143+#if (NGX_HTTP_UPSTREAM_CHECK) 144+ if (!server[i].down) { 145+ peers->peer[n].check_index = 146+ ngx_http_upstream_check_add_peer(cf, us, &server[i].addrs[j]); 147+ } else { 148+ peers->peer[n].check_index = (ngx_uint_t) NGX_ERROR; 149+ } 150+#endif 151 n++; 152 } 153 } 154@@ -148,6 +159,15 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf, 155 peer[n].fail_timeout = server[i].fail_timeout; 156 peer[n].down = server[i].down; 157 peer[n].server = server[i].name; 158+#if (NGX_HTTP_UPSTREAM_CHECK) 159+ if (!server[i].down) { 160+ backup->peer[n].check_index = 161+ ngx_http_upstream_check_add_peer(cf, us, &server[i].addrs[j]); 162+ } 163+ else { 164+ backup->peer[n].check_index = (ngx_uint_t) NGX_ERROR; 165+ } 166+#endif 167 n++; 168 } 169 } 170@@ -207,6 +227,9 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf, 171 peer[i].current_weight = 0; 172 peer[i].max_fails = 1; 173 peer[i].fail_timeout = 10; 174+#if (NGX_HTTP_UPSTREAM_CHECK) 175+ peers->peer[i].check_index = (ngx_uint_t) NGX_ERROR; 176+#endif 177 } 178 179 us->peer.data = peers; 180@@ -316,7 +339,9 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r, 181 peer[0].current_weight = 0; 182 peer[0].max_fails = 1; 183 peer[0].fail_timeout = 10; 184- 185+#if (NGX_HTTP_UPSTREAM_CHECK) 186+ peers->peer[0].check_index = (ngx_uint_t) NGX_ERROR; 187+#endif 188 } else { 189 190 for (i = 0; i < ur->naddrs; i++) { 191@@ -356,6 +381,9 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r, 192 peer[i].current_weight = 0; 193 peer[i].max_fails = 1; 194 peer[i].fail_timeout = 10; 195+#if (NGX_HTTP_UPSTREAM_CHECK) 196+ peers->peer[i].check_index = (ngx_uint_t) NGX_ERROR; 197+#endif 198 } 199 } 200 201@@ -415,6 +443,12 @@ ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, void *data) 202 goto failed; 203 } 204 205+#if (NGX_HTTP_UPSTREAM_CHECK) 206+ if (ngx_http_upstream_check_peer_down(peer->check_index)) { 207+ goto failed; 208+ } 209+#endif 210+ 211 } else { 212 213 /* there are several peers */ 214@@ -507,6 +541,12 @@ ngx_http_upstream_get_peer(ngx_http_upstream_rr_peer_data_t *rrp) 215 continue; 216 } 217 218+#if (NGX_HTTP_UPSTREAM_CHECK) 219+ if (ngx_http_upstream_check_peer_down(peer->check_index)) { 220+ continue; 221+ } 222+#endif 223+ 224 if (peer->max_fails 225 && peer->fails >= peer->max_fails 226 && now - peer->checked <= peer->fail_timeout) 227diff --git a/src/http/ngx_http_upstream_round_robin.h b/src/http/ngx_http_upstream_round_robin.h 228index 9db82a6..6e19a65 100644 229--- a/src/http/ngx_http_upstream_round_robin.h 230+++ b/src/http/ngx_http_upstream_round_robin.h 231@@ -31,6 +31,10 @@ typedef struct { 232 ngx_uint_t max_fails; 233 time_t fail_timeout; 234 235+#if (NGX_HTTP_UPSTREAM_CHECK) 236+ ngx_uint_t check_index; 237+#endif 238+ 239 ngx_uint_t down; /* unsigned down:1; */ 240 241 #if (NGX_HTTP_SSL) 242