summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2013-03-29 18:16:27 +0000
committerMaxim Dounin <mdounin@mdounin.ru>2013-03-29 18:16:27 +0000
commit4e2bbc23c1564ac1458dc17c5c6c38ca52ae012d (patch)
treeab17bf42ecc2266a900993b12bdd0b8c5f6c7685
parentf064449ea7067b2efe537c31c43657cd5aa6488a (diff)
downloadnginx-4e2bbc23c1564ac1458dc17c5c6c38ca52ae012d.tar.gz
Merge of r5133, r5134: peer.free() and peer.get() balance.
*) Upstream: only call peer.free() if peer.get() selected a peer. *) Upstream: removed double-free workarounds in peer.free() methods.
-rw-r--r--src/http/modules/ngx_http_upstream_keepalive_module.c12
-rw-r--r--src/http/modules/ngx_http_upstream_least_conn_module.c4
-rw-r--r--src/http/ngx_http_upstream.c17
-rw-r--r--src/http/ngx_http_upstream_round_robin.c4
4 files changed, 11 insertions, 26 deletions
diff --git a/src/http/modules/ngx_http_upstream_keepalive_module.c b/src/http/modules/ngx_http_upstream_keepalive_module.c
index a2ad5aa8d..eed117404 100644
--- a/src/http/modules/ngx_http_upstream_keepalive_module.c
+++ b/src/http/modules/ngx_http_upstream_keepalive_module.c
@@ -37,8 +37,6 @@ typedef struct {
ngx_event_save_peer_session_pt original_save_session;
#endif
- ngx_uint_t failed; /* unsigned:1 */
-
} ngx_http_upstream_keepalive_peer_data_t;
@@ -220,8 +218,6 @@ ngx_http_upstream_get_keepalive_peer(ngx_peer_connection_t *pc, void *data)
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0,
"get keepalive peer");
- kp->failed = 0;
-
/* ask balancer */
rc = kp->original_get_peer(pc, kp->data);
@@ -282,18 +278,12 @@ ngx_http_upstream_free_keepalive_peer(ngx_peer_connection_t *pc, void *data,
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0,
"free keepalive peer");
- /* remember failed state - peer.free() may be called more than once */
-
- if (state & NGX_PEER_FAILED) {
- kp->failed = 1;
- }
-
/* cache valid connections */
u = kp->upstream;
c = pc->connection;
- if (kp->failed
+ if (state & NGX_PEER_FAILED
|| c == NULL
|| c->read->eof
|| c->read->error
diff --git a/src/http/modules/ngx_http_upstream_least_conn_module.c b/src/http/modules/ngx_http_upstream_least_conn_module.c
index bd2f1bc9e..6066ed2bb 100644
--- a/src/http/modules/ngx_http_upstream_least_conn_module.c
+++ b/src/http/modules/ngx_http_upstream_least_conn_module.c
@@ -353,10 +353,6 @@ ngx_http_upstream_free_least_conn_peer(ngx_peer_connection_t *pc,
return;
}
- if (state == 0 && pc->tries == 0) {
- return;
- }
-
lcp->conns[lcp->rrp.current]--;
lcp->free_rr_peer(pc, &lcp->rrp, state);
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index 84fd8b187..dc1283a20 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -2846,14 +2846,16 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
ngx_http_busy_unlock(u->conf->busy_lock, &u->busy_lock);
#endif
- if (ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_404) {
- state = NGX_PEER_NEXT;
- } else {
- state = NGX_PEER_FAILED;
- }
+ if (u->peer.sockaddr) {
+
+ if (ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_404) {
+ state = NGX_PEER_NEXT;
+ } else {
+ state = NGX_PEER_FAILED;
+ }
- if (ft_type != NGX_HTTP_UPSTREAM_FT_NOLIVE) {
u->peer.free(&u->peer, u->peer.data, state);
+ u->peer.sockaddr = NULL;
}
if (ft_type == NGX_HTTP_UPSTREAM_FT_TIMEOUT) {
@@ -3013,8 +3015,9 @@ ngx_http_upstream_finalize_request(ngx_http_request_t *r,
u->finalize_request(r, rc);
- if (u->peer.free) {
+ if (u->peer.free && u->peer.sockaddr) {
u->peer.free(&u->peer, u->peer.data, 0);
+ u->peer.sockaddr = NULL;
}
if (u->peer.connection) {
diff --git a/src/http/ngx_http_upstream_round_robin.c b/src/http/ngx_http_upstream_round_robin.c
index 61dce69cb..c9ecfb22a 100644
--- a/src/http/ngx_http_upstream_round_robin.c
+++ b/src/http/ngx_http_upstream_round_robin.c
@@ -584,10 +584,6 @@ ngx_http_upstream_free_round_robin_peer(ngx_peer_connection_t *pc, void *data,
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0,
"free rr peer %ui %ui", pc->tries, state);
- if (state == 0 && pc->tries == 0) {
- return;
- }
-
/* TODO: NGX_PEER_KEEPALIVE */
if (rrp->peers->single) {