Created
April 8, 2017 19:53
-
-
Save knazarov/4be8934f015d523aa85dcdca47478241 to your computer and use it in GitHub Desktop.
A patch to close upstream connections on setting the "down" flag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- ./bundle/nginx-1.11.2/src/stream/ngx_stream_proxy_module.c 2017-04-06 15:55:53.000000000 +0300 | |
+++ ./bundle/nginx-1.11.2/src/stream/ngx_stream_proxy_module.c 2017-04-08 22:50:56.000000000 +0300 | |
@@ -1,4 +1,3 @@ | |
- | |
/* | |
* Copyright (C) Roman Arutyunyan | |
* Copyright (C) Nginx, Inc. | |
@@ -1152,6 +1151,10 @@ | |
ngx_log_handler_pt handler; | |
ngx_stream_upstream_t *u; | |
ngx_stream_proxy_srv_conf_t *pscf; | |
+ ngx_stream_upstream_srv_conf_t *uscf; | |
+ ngx_stream_upstream_rr_peers_t *peers; | |
+ ngx_stream_upstream_rr_peer_t *peer; | |
+ ngx_uint_t i; | |
u = s->upstream; | |
@@ -1174,6 +1177,35 @@ | |
} | |
pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); | |
+ uscf = pscf->upstream; | |
+ | |
+ peers = uscf->peer.data; | |
+ | |
+ if (peers != NULL) { | |
+ for (i = 0; i < peers->number; i++) { | |
+ peer = &peers->peer[i]; | |
+ | |
+ if (peer->down && &peer->name == u->peer.name) { | |
+ ngx_log_error(NGX_LOG_ERR, c->log, 0, "Closing connection to %V", &peer->name); | |
+ ngx_stream_proxy_finalize(s, NGX_DECLINED); | |
+ return; | |
+ } | |
+ } | |
+ | |
+ peers = peers->next; | |
+ | |
+ if (peers != NULL) { | |
+ for (i = 0; i < peers->number; i++) { | |
+ peer = &peers->peer[i]; | |
+ | |
+ if (peer->down && &peer->name == u->peer.name) { | |
+ ngx_log_error(NGX_LOG_ERR, c->log, 0, "Closing connection to %V", &peer->name); | |
+ ngx_stream_proxy_finalize(s, NGX_DECLINED); | |
+ return; | |
+ } | |
+ } | |
+ } | |
+ } | |
if (from_upstream) { | |
src = pc; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment