Mercurial > hg > nginx
annotate src/http/ngx_http_upstream_round_robin.c @ 6785:d1d0dd69a419
Upstream: added the ngx_http_upstream_resolved_t.name field.
This fixes inconsistency in what is stored in the "host" field.
Normally it would contain the "host" part of the parsed URL
(e.g., proxy_pass with variables), but for the case of an
implicit upstream specified with literal address it contained
the text representation of the socket address (that is, host
including port for IP).
Now the "host" field always contains the "host" part of the URL,
while the text representation of the socket address is stored
in the newly added "name" field.
The ngx_http_upstream_create_round_robin_peer() function was
modified accordingly in a way to be compatible with the code
that does not know about the new "name" field.
The "stream" code was similarly modified except for not adding
compatibility in ngx_stream_upstream_create_round_robin_peer().
This change is also a prerequisite for the next change.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Mon, 31 Oct 2016 18:33:33 +0300 |
parents | fd5c2781460b |
children | 696df3ac27ac |
rev | line source |
---|---|
884 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
884 | 5 */ |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_http.h> | |
11 | |
12 | |
5831
575175ebf4b4
Upstream: included backup peers into peer.tries.
Roman Arutyunyan <arut@nginx.com>
parents:
5756
diff
changeset
|
13 #define ngx_http_upstream_tries(p) ((p)->number \ |
575175ebf4b4
Upstream: included backup peers into peer.tries.
Roman Arutyunyan <arut@nginx.com>
parents:
5756
diff
changeset
|
14 + ((p)->next ? (p)->next->number : 0)) |
575175ebf4b4
Upstream: included backup peers into peer.tries.
Roman Arutyunyan <arut@nginx.com>
parents:
5756
diff
changeset
|
15 |
575175ebf4b4
Upstream: included backup peers into peer.tries.
Roman Arutyunyan <arut@nginx.com>
parents:
5756
diff
changeset
|
16 |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
17 static ngx_http_upstream_rr_peer_t *ngx_http_upstream_get_peer( |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
18 ngx_http_upstream_rr_peer_data_t *rrp); |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
19 |
3964
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
20 #if (NGX_HTTP_SSL) |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
21 |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
22 static ngx_int_t ngx_http_upstream_empty_set_session(ngx_peer_connection_t *pc, |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
23 void *data); |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
24 static void ngx_http_upstream_empty_save_session(ngx_peer_connection_t *pc, |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
25 void *data); |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
26 |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
27 #endif |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
28 |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
29 |
884 | 30 ngx_int_t |
31 ngx_http_upstream_init_round_robin(ngx_conf_t *cf, | |
32 ngx_http_upstream_srv_conf_t *us) | |
33 { | |
34 ngx_url_t u; | |
4655
382c523d253a
Upstream: weights support in ip_hash balancer.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4622
diff
changeset
|
35 ngx_uint_t i, j, n, w; |
884 | 36 ngx_http_upstream_server_t *server; |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
37 ngx_http_upstream_rr_peer_t *peer, **peerp; |
1378 | 38 ngx_http_upstream_rr_peers_t *peers, *backup; |
884 | 39 |
40 us->peer.init = ngx_http_upstream_init_round_robin_peer; | |
41 | |
42 if (us->servers) { | |
43 server = us->servers->elts; | |
44 | |
1378 | 45 n = 0; |
4655
382c523d253a
Upstream: weights support in ip_hash balancer.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4622
diff
changeset
|
46 w = 0; |
1378 | 47 |
884 | 48 for (i = 0; i < us->servers->nelts; i++) { |
1378 | 49 if (server[i].backup) { |
50 continue; | |
51 } | |
52 | |
884 | 53 n += server[i].naddrs; |
4655
382c523d253a
Upstream: weights support in ip_hash balancer.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4622
diff
changeset
|
54 w += server[i].naddrs * server[i].weight; |
884 | 55 } |
56 | |
4569
1db899642518
Upstream: reject upstreams without normal servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
57 if (n == 0) { |
1db899642518
Upstream: reject upstreams without normal servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
58 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
1db899642518
Upstream: reject upstreams without normal servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
59 "no servers in upstream \"%V\" in %s:%ui", |
1db899642518
Upstream: reject upstreams without normal servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
60 &us->host, us->file_name, us->line); |
1db899642518
Upstream: reject upstreams without normal servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
61 return NGX_ERROR; |
1db899642518
Upstream: reject upstreams without normal servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
62 } |
1db899642518
Upstream: reject upstreams without normal servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
63 |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
64 peers = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t)); |
884 | 65 if (peers == NULL) { |
66 return NGX_ERROR; | |
67 } | |
68 | |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
69 peer = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peer_t) * n); |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
70 if (peer == NULL) { |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
71 return NGX_ERROR; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
72 } |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
73 |
1378 | 74 peers->single = (n == 1); |
884 | 75 peers->number = n; |
4655
382c523d253a
Upstream: weights support in ip_hash balancer.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4622
diff
changeset
|
76 peers->weighted = (w != n); |
382c523d253a
Upstream: weights support in ip_hash balancer.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4622
diff
changeset
|
77 peers->total_weight = w; |
884 | 78 peers->name = &us->host; |
79 | |
80 n = 0; | |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
81 peerp = &peers->peer; |
884 | 82 |
83 for (i = 0; i < us->servers->nelts; i++) { | |
5429
e6a1623f87bc
Upstream: optimize loops in ngx_http_upstream_init_round_robin().
Xiaochen Wang <wangxiaochen0@gmail.com>
parents:
5220
diff
changeset
|
84 if (server[i].backup) { |
e6a1623f87bc
Upstream: optimize loops in ngx_http_upstream_init_round_robin().
Xiaochen Wang <wangxiaochen0@gmail.com>
parents:
5220
diff
changeset
|
85 continue; |
e6a1623f87bc
Upstream: optimize loops in ngx_http_upstream_init_round_robin().
Xiaochen Wang <wangxiaochen0@gmail.com>
parents:
5220
diff
changeset
|
86 } |
e6a1623f87bc
Upstream: optimize loops in ngx_http_upstream_init_round_robin().
Xiaochen Wang <wangxiaochen0@gmail.com>
parents:
5220
diff
changeset
|
87 |
884 | 88 for (j = 0; j < server[i].naddrs; j++) { |
5720
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
89 peer[n].sockaddr = server[i].addrs[j].sockaddr; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
90 peer[n].socklen = server[i].addrs[j].socklen; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
91 peer[n].name = server[i].addrs[j].name; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
92 peer[n].weight = server[i].weight; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
93 peer[n].effective_weight = server[i].weight; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
94 peer[n].current_weight = 0; |
6705 | 95 peer[n].max_conns = server[i].max_conns; |
5720
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
96 peer[n].max_fails = server[i].max_fails; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
97 peer[n].fail_timeout = server[i].fail_timeout; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
98 peer[n].down = server[i].down; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
99 peer[n].server = server[i].name; |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
100 |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
101 *peerp = &peer[n]; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
102 peerp = &peer[n].next; |
884 | 103 n++; |
104 } | |
105 } | |
106 | |
107 us->peer.data = peers; | |
108 | |
1378 | 109 /* backup servers */ |
110 | |
111 n = 0; | |
4655
382c523d253a
Upstream: weights support in ip_hash balancer.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4622
diff
changeset
|
112 w = 0; |
1378 | 113 |
114 for (i = 0; i < us->servers->nelts; i++) { | |
115 if (!server[i].backup) { | |
116 continue; | |
117 } | |
118 | |
119 n += server[i].naddrs; | |
4655
382c523d253a
Upstream: weights support in ip_hash balancer.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4622
diff
changeset
|
120 w += server[i].naddrs * server[i].weight; |
1378 | 121 } |
122 | |
123 if (n == 0) { | |
124 return NGX_OK; | |
125 } | |
126 | |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
127 backup = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t)); |
1378 | 128 if (backup == NULL) { |
129 return NGX_ERROR; | |
130 } | |
131 | |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
132 peer = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peer_t) * n); |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
133 if (peer == NULL) { |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
134 return NGX_ERROR; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
135 } |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
136 |
1378 | 137 peers->single = 0; |
138 backup->single = 0; | |
139 backup->number = n; | |
4655
382c523d253a
Upstream: weights support in ip_hash balancer.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4622
diff
changeset
|
140 backup->weighted = (w != n); |
382c523d253a
Upstream: weights support in ip_hash balancer.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4622
diff
changeset
|
141 backup->total_weight = w; |
1378 | 142 backup->name = &us->host; |
143 | |
144 n = 0; | |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
145 peerp = &backup->peer; |
1378 | 146 |
147 for (i = 0; i < us->servers->nelts; i++) { | |
5429
e6a1623f87bc
Upstream: optimize loops in ngx_http_upstream_init_round_robin().
Xiaochen Wang <wangxiaochen0@gmail.com>
parents:
5220
diff
changeset
|
148 if (!server[i].backup) { |
e6a1623f87bc
Upstream: optimize loops in ngx_http_upstream_init_round_robin().
Xiaochen Wang <wangxiaochen0@gmail.com>
parents:
5220
diff
changeset
|
149 continue; |
e6a1623f87bc
Upstream: optimize loops in ngx_http_upstream_init_round_robin().
Xiaochen Wang <wangxiaochen0@gmail.com>
parents:
5220
diff
changeset
|
150 } |
e6a1623f87bc
Upstream: optimize loops in ngx_http_upstream_init_round_robin().
Xiaochen Wang <wangxiaochen0@gmail.com>
parents:
5220
diff
changeset
|
151 |
1378 | 152 for (j = 0; j < server[i].naddrs; j++) { |
5720
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
153 peer[n].sockaddr = server[i].addrs[j].sockaddr; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
154 peer[n].socklen = server[i].addrs[j].socklen; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
155 peer[n].name = server[i].addrs[j].name; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
156 peer[n].weight = server[i].weight; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
157 peer[n].effective_weight = server[i].weight; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
158 peer[n].current_weight = 0; |
6705 | 159 peer[n].max_conns = server[i].max_conns; |
5720
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
160 peer[n].max_fails = server[i].max_fails; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
161 peer[n].fail_timeout = server[i].fail_timeout; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
162 peer[n].down = server[i].down; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
163 peer[n].server = server[i].name; |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
164 |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
165 *peerp = &peer[n]; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
166 peerp = &peer[n].next; |
1378 | 167 n++; |
168 } | |
169 } | |
170 | |
171 peers->next = backup; | |
172 | |
884 | 173 return NGX_OK; |
174 } | |
175 | |
176 | |
177 /* an upstream implicitly defined by proxy_pass, etc. */ | |
178 | |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4991
diff
changeset
|
179 if (us->port == 0) { |
906 | 180 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
181 "no port in upstream \"%V\" in %s:%ui", | |
1489
56f1ea5baabb
u_char* is enough to keep file name
Igor Sysoev <igor@sysoev.ru>
parents:
1465
diff
changeset
|
182 &us->host, us->file_name, us->line); |
906 | 183 return NGX_ERROR; |
184 } | |
185 | |
884 | 186 ngx_memzero(&u, sizeof(ngx_url_t)); |
187 | |
188 u.host = us->host; | |
5005
c9059bd5445b
Fixed "proxy_pass" with IP address and no port (ticket #276).
Ruslan Ermilov <ru@nginx.com>
parents:
4991
diff
changeset
|
189 u.port = us->port; |
884 | 190 |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1556
diff
changeset
|
191 if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) { |
884 | 192 if (u.err) { |
193 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
896
f247db60fc85
fix fastcgi and memcached upstreams
Igor Sysoev <igor@sysoev.ru>
parents:
884
diff
changeset
|
194 "%s in upstream \"%V\" in %s:%ui", |
1489
56f1ea5baabb
u_char* is enough to keep file name
Igor Sysoev <igor@sysoev.ru>
parents:
1465
diff
changeset
|
195 u.err, &us->host, us->file_name, us->line); |
884 | 196 } |
197 | |
198 return NGX_ERROR; | |
199 } | |
200 | |
201 n = u.naddrs; | |
202 | |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
203 peers = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t)); |
884 | 204 if (peers == NULL) { |
205 return NGX_ERROR; | |
206 } | |
207 | |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
208 peer = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peer_t) * n); |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
209 if (peer == NULL) { |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
210 return NGX_ERROR; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
211 } |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
212 |
1378 | 213 peers->single = (n == 1); |
884 | 214 peers->number = n; |
4655
382c523d253a
Upstream: weights support in ip_hash balancer.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4622
diff
changeset
|
215 peers->weighted = 0; |
382c523d253a
Upstream: weights support in ip_hash balancer.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4622
diff
changeset
|
216 peers->total_weight = n; |
884 | 217 peers->name = &us->host; |
218 | |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
219 peerp = &peers->peer; |
5720
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
220 |
884 | 221 for (i = 0; i < u.naddrs; i++) { |
5720
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
222 peer[i].sockaddr = u.addrs[i].sockaddr; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
223 peer[i].socklen = u.addrs[i].socklen; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
224 peer[i].name = u.addrs[i].name; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
225 peer[i].weight = 1; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
226 peer[i].effective_weight = 1; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
227 peer[i].current_weight = 0; |
6705 | 228 peer[i].max_conns = 0; |
5720
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
229 peer[i].max_fails = 1; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
230 peer[i].fail_timeout = 10; |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
231 *peerp = &peer[i]; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
232 peerp = &peer[i].next; |
884 | 233 } |
234 | |
235 us->peer.data = peers; | |
236 | |
1378 | 237 /* implicitly defined upstream has no backup servers */ |
238 | |
884 | 239 return NGX_OK; |
240 } | |
241 | |
242 | |
243 ngx_int_t | |
244 ngx_http_upstream_init_round_robin_peer(ngx_http_request_t *r, | |
245 ngx_http_upstream_srv_conf_t *us) | |
246 { | |
247 ngx_uint_t n; | |
248 ngx_http_upstream_rr_peer_data_t *rrp; | |
249 | |
250 rrp = r->upstream->peer.data; | |
251 | |
252 if (rrp == NULL) { | |
253 rrp = ngx_palloc(r->pool, sizeof(ngx_http_upstream_rr_peer_data_t)); | |
254 if (rrp == NULL) { | |
255 return NGX_ERROR; | |
256 } | |
257 | |
258 r->upstream->peer.data = rrp; | |
259 } | |
260 | |
261 rrp->peers = us->peer.data; | |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
262 rrp->current = NULL; |
6712
fd5c2781460b
Modules compatibility: upstream config field.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6705
diff
changeset
|
263 rrp->config = 0; |
884 | 264 |
4011
9d4cbb09ae8b
Upstream: properly allocate memory for tried flags.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4010
diff
changeset
|
265 n = rrp->peers->number; |
9d4cbb09ae8b
Upstream: properly allocate memory for tried flags.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4010
diff
changeset
|
266 |
9d4cbb09ae8b
Upstream: properly allocate memory for tried flags.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4010
diff
changeset
|
267 if (rrp->peers->next && rrp->peers->next->number > n) { |
9d4cbb09ae8b
Upstream: properly allocate memory for tried flags.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4010
diff
changeset
|
268 n = rrp->peers->next->number; |
9d4cbb09ae8b
Upstream: properly allocate memory for tried flags.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4010
diff
changeset
|
269 } |
9d4cbb09ae8b
Upstream: properly allocate memory for tried flags.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4010
diff
changeset
|
270 |
9d4cbb09ae8b
Upstream: properly allocate memory for tried flags.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4010
diff
changeset
|
271 if (n <= 8 * sizeof(uintptr_t)) { |
884 | 272 rrp->tried = &rrp->data; |
273 rrp->data = 0; | |
274 | |
275 } else { | |
4011
9d4cbb09ae8b
Upstream: properly allocate memory for tried flags.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4010
diff
changeset
|
276 n = (n + (8 * sizeof(uintptr_t) - 1)) / (8 * sizeof(uintptr_t)); |
884 | 277 |
278 rrp->tried = ngx_pcalloc(r->pool, n * sizeof(uintptr_t)); | |
279 if (rrp->tried == NULL) { | |
280 return NGX_ERROR; | |
281 } | |
282 } | |
283 | |
284 r->upstream->peer.get = ngx_http_upstream_get_round_robin_peer; | |
285 r->upstream->peer.free = ngx_http_upstream_free_round_robin_peer; | |
5831
575175ebf4b4
Upstream: included backup peers into peer.tries.
Roman Arutyunyan <arut@nginx.com>
parents:
5756
diff
changeset
|
286 r->upstream->peer.tries = ngx_http_upstream_tries(rrp->peers); |
884 | 287 #if (NGX_HTTP_SSL) |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
288 r->upstream->peer.set_session = |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
289 ngx_http_upstream_set_round_robin_peer_session; |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
290 r->upstream->peer.save_session = |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
291 ngx_http_upstream_save_round_robin_peer_session; |
884 | 292 #endif |
293 | |
294 return NGX_OK; | |
295 } | |
296 | |
297 | |
298 ngx_int_t | |
1658 | 299 ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r, |
300 ngx_http_upstream_resolved_t *ur) | |
301 { | |
302 u_char *p; | |
303 size_t len; | |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
304 socklen_t socklen; |
1658 | 305 ngx_uint_t i, n; |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
306 struct sockaddr *sockaddr; |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
307 ngx_http_upstream_rr_peer_t *peer, **peerp; |
1658 | 308 ngx_http_upstream_rr_peers_t *peers; |
309 ngx_http_upstream_rr_peer_data_t *rrp; | |
310 | |
311 rrp = r->upstream->peer.data; | |
312 | |
313 if (rrp == NULL) { | |
314 rrp = ngx_palloc(r->pool, sizeof(ngx_http_upstream_rr_peer_data_t)); | |
315 if (rrp == NULL) { | |
316 return NGX_ERROR; | |
317 } | |
318 | |
319 r->upstream->peer.data = rrp; | |
320 } | |
321 | |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
322 peers = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_rr_peers_t)); |
1658 | 323 if (peers == NULL) { |
324 return NGX_ERROR; | |
325 } | |
326 | |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
327 peer = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_rr_peer_t) |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
328 * ur->naddrs); |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
329 if (peer == NULL) { |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
330 return NGX_ERROR; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
331 } |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
332 |
1658 | 333 peers->single = (ur->naddrs == 1); |
334 peers->number = ur->naddrs; | |
335 peers->name = &ur->host; | |
336 | |
2422
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2204
diff
changeset
|
337 if (ur->sockaddr) { |
5720
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
338 peer[0].sockaddr = ur->sockaddr; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
339 peer[0].socklen = ur->socklen; |
6785
d1d0dd69a419
Upstream: added the ngx_http_upstream_resolved_t.name field.
Ruslan Ermilov <ru@nginx.com>
parents:
6712
diff
changeset
|
340 peer[0].name = ur->name.data ? ur->name : ur->host; |
5720
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
341 peer[0].weight = 1; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
342 peer[0].effective_weight = 1; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
343 peer[0].current_weight = 0; |
6705 | 344 peer[0].max_conns = 0; |
5720
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
345 peer[0].max_fails = 1; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
346 peer[0].fail_timeout = 10; |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
347 peers->peer = peer; |
1658 | 348 |
2422
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2204
diff
changeset
|
349 } else { |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
350 peerp = &peers->peer; |
2422
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2204
diff
changeset
|
351 |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2204
diff
changeset
|
352 for (i = 0; i < ur->naddrs; i++) { |
1658 | 353 |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
354 socklen = ur->addrs[i].socklen; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
355 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
356 sockaddr = ngx_palloc(r->pool, socklen); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
357 if (sockaddr == NULL) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
358 return NGX_ERROR; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
359 } |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
360 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
361 ngx_memcpy(sockaddr, ur->addrs[i].sockaddr, socklen); |
6593
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6474
diff
changeset
|
362 ngx_inet_set_port(sockaddr, ur->port); |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
363 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
364 p = ngx_pnalloc(r->pool, NGX_SOCKADDR_STRLEN); |
2422
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2204
diff
changeset
|
365 if (p == NULL) { |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2204
diff
changeset
|
366 return NGX_ERROR; |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2204
diff
changeset
|
367 } |
1658 | 368 |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
369 len = ngx_sock_ntop(sockaddr, socklen, p, NGX_SOCKADDR_STRLEN, 1); |
1658 | 370 |
5720
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
371 peer[i].sockaddr = sockaddr; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
372 peer[i].socklen = socklen; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
373 peer[i].name.len = len; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
374 peer[i].name.data = p; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
375 peer[i].weight = 1; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
376 peer[i].effective_weight = 1; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
377 peer[i].current_weight = 0; |
6705 | 378 peer[i].max_conns = 0; |
5720
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
379 peer[i].max_fails = 1; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
380 peer[i].fail_timeout = 10; |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
381 *peerp = &peer[i]; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
382 peerp = &peer[i].next; |
2422
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2204
diff
changeset
|
383 } |
1658 | 384 } |
385 | |
386 rrp->peers = peers; | |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
387 rrp->current = NULL; |
6712
fd5c2781460b
Modules compatibility: upstream config field.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6705
diff
changeset
|
388 rrp->config = 0; |
1658 | 389 |
390 if (rrp->peers->number <= 8 * sizeof(uintptr_t)) { | |
391 rrp->tried = &rrp->data; | |
392 rrp->data = 0; | |
393 | |
394 } else { | |
395 n = (rrp->peers->number + (8 * sizeof(uintptr_t) - 1)) | |
396 / (8 * sizeof(uintptr_t)); | |
397 | |
398 rrp->tried = ngx_pcalloc(r->pool, n * sizeof(uintptr_t)); | |
399 if (rrp->tried == NULL) { | |
400 return NGX_ERROR; | |
401 } | |
402 } | |
403 | |
404 r->upstream->peer.get = ngx_http_upstream_get_round_robin_peer; | |
405 r->upstream->peer.free = ngx_http_upstream_free_round_robin_peer; | |
5831
575175ebf4b4
Upstream: included backup peers into peer.tries.
Roman Arutyunyan <arut@nginx.com>
parents:
5756
diff
changeset
|
406 r->upstream->peer.tries = ngx_http_upstream_tries(rrp->peers); |
1658 | 407 #if (NGX_HTTP_SSL) |
3964
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
408 r->upstream->peer.set_session = ngx_http_upstream_empty_set_session; |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
409 r->upstream->peer.save_session = ngx_http_upstream_empty_save_session; |
1658 | 410 #endif |
411 | |
412 return NGX_OK; | |
413 } | |
414 | |
415 | |
416 ngx_int_t | |
884 | 417 ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, void *data) |
418 { | |
419 ngx_http_upstream_rr_peer_data_t *rrp = data; | |
420 | |
1378 | 421 ngx_int_t rc; |
422 ngx_uint_t i, n; | |
423 ngx_http_upstream_rr_peer_t *peer; | |
424 ngx_http_upstream_rr_peers_t *peers; | |
884 | 425 |
426 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, | |
427 "get rr peer, try: %ui", pc->tries); | |
428 | |
429 pc->cached = 0; | |
430 pc->connection = NULL; | |
431 | |
5720
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
432 peers = rrp->peers; |
6102 | 433 ngx_http_upstream_rr_peers_wlock(peers); |
5720
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
434 |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
435 if (peers->single) { |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
436 peer = peers->peer; |
884 | 437 |
4914
dcb853acae97
Upstream: honor the "down" flag for a single server.
Ruslan Ermilov <ru@nginx.com>
parents:
4655
diff
changeset
|
438 if (peer->down) { |
dcb853acae97
Upstream: honor the "down" flag for a single server.
Ruslan Ermilov <ru@nginx.com>
parents:
4655
diff
changeset
|
439 goto failed; |
dcb853acae97
Upstream: honor the "down" flag for a single server.
Ruslan Ermilov <ru@nginx.com>
parents:
4655
diff
changeset
|
440 } |
dcb853acae97
Upstream: honor the "down" flag for a single server.
Ruslan Ermilov <ru@nginx.com>
parents:
4655
diff
changeset
|
441 |
6705 | 442 if (peer->max_conns && peer->conns >= peer->max_conns) { |
443 goto failed; | |
444 } | |
445 | |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
446 rrp->current = peer; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
447 |
884 | 448 } else { |
449 | |
450 /* there are several peers */ | |
451 | |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
452 peer = ngx_http_upstream_get_peer(rrp); |
884 | 453 |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
454 if (peer == NULL) { |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
455 goto failed; |
884 | 456 } |
457 | |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
458 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
459 "get rr peer, current: %p %i", |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
460 peer, peer->current_weight); |
884 | 461 } |
462 | |
463 pc->sockaddr = peer->sockaddr; | |
464 pc->socklen = peer->socklen; | |
465 pc->name = &peer->name; | |
466 | |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
467 peer->conns++; |
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
468 |
6102 | 469 ngx_http_upstream_rr_peers_unlock(peers); |
884 | 470 |
471 return NGX_OK; | |
472 | |
473 failed: | |
474 | |
1378 | 475 if (peers->next) { |
476 | |
477 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0, "backup servers"); | |
478 | |
479 rrp->peers = peers->next; | |
480 | |
4991
a384c60d55f3
Upstream: fixed state resetting when switching to backup servers.
Valentin Bartenev <vbart@nginx.com>
parents:
4914
diff
changeset
|
481 n = (rrp->peers->number + (8 * sizeof(uintptr_t) - 1)) |
a384c60d55f3
Upstream: fixed state resetting when switching to backup servers.
Valentin Bartenev <vbart@nginx.com>
parents:
4914
diff
changeset
|
482 / (8 * sizeof(uintptr_t)); |
a384c60d55f3
Upstream: fixed state resetting when switching to backup servers.
Valentin Bartenev <vbart@nginx.com>
parents:
4914
diff
changeset
|
483 |
1389 | 484 for (i = 0; i < n; i++) { |
6474 | 485 rrp->tried[i] = 0; |
1378 | 486 } |
487 | |
6102 | 488 ngx_http_upstream_rr_peers_unlock(peers); |
489 | |
1378 | 490 rc = ngx_http_upstream_get_round_robin_peer(pc, rrp); |
491 | |
492 if (rc != NGX_BUSY) { | |
493 return rc; | |
494 } | |
495 | |
6102 | 496 ngx_http_upstream_rr_peers_wlock(peers); |
1378 | 497 } |
498 | |
6102 | 499 ngx_http_upstream_rr_peers_unlock(peers); |
884 | 500 |
1378 | 501 pc->name = peers->name; |
884 | 502 |
503 return NGX_BUSY; | |
504 } | |
505 | |
506 | |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
507 static ngx_http_upstream_rr_peer_t * |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
508 ngx_http_upstream_get_peer(ngx_http_upstream_rr_peer_data_t *rrp) |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
509 { |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
510 time_t now; |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
511 uintptr_t m; |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
512 ngx_int_t total; |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
513 ngx_uint_t i, n, p; |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
514 ngx_http_upstream_rr_peer_t *peer, *best; |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
515 |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
516 now = ngx_time(); |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
517 |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
518 best = NULL; |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
519 total = 0; |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
520 |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
521 #if (NGX_SUPPRESS_WARN) |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
522 p = 0; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
523 #endif |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
524 |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
525 for (peer = rrp->peers->peer, i = 0; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
526 peer; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
527 peer = peer->next, i++) |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
528 { |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
529 n = i / (8 * sizeof(uintptr_t)); |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
530 m = (uintptr_t) 1 << i % (8 * sizeof(uintptr_t)); |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
531 |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
532 if (rrp->tried[n] & m) { |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
533 continue; |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
534 } |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
535 |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
536 if (peer->down) { |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
537 continue; |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
538 } |
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
539 |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
540 if (peer->max_fails |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
541 && peer->fails >= peer->max_fails |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
542 && now - peer->checked <= peer->fail_timeout) |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
543 { |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
544 continue; |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
545 } |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
546 |
6705 | 547 if (peer->max_conns && peer->conns >= peer->max_conns) { |
548 continue; | |
549 } | |
550 | |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
551 peer->current_weight += peer->effective_weight; |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
552 total += peer->effective_weight; |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
553 |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
554 if (peer->effective_weight < peer->weight) { |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
555 peer->effective_weight++; |
4010
74a93d3fdd85
Fixing cpu hog with all upstream servers marked "down".
Maxim Dounin <mdounin@mdounin.ru>
parents:
3964
diff
changeset
|
556 } |
74a93d3fdd85
Fixing cpu hog with all upstream servers marked "down".
Maxim Dounin <mdounin@mdounin.ru>
parents:
3964
diff
changeset
|
557 |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
558 if (best == NULL || peer->current_weight > best->current_weight) { |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
559 best = peer; |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
560 p = i; |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
561 } |
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
562 } |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
563 |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
564 if (best == NULL) { |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
565 return NULL; |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
566 } |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
567 |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
568 rrp->current = best; |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
569 |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
570 n = p / (8 * sizeof(uintptr_t)); |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
571 m = (uintptr_t) 1 << p % (8 * sizeof(uintptr_t)); |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
572 |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
573 rrp->tried[n] |= m; |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
574 |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
575 best->current_weight -= total; |
5220
1d68b502088c
Upstream: fixed fail_timeout and max_fails > 1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5136
diff
changeset
|
576 |
1d68b502088c
Upstream: fixed fail_timeout and max_fails > 1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5136
diff
changeset
|
577 if (now - best->checked > best->fail_timeout) { |
1d68b502088c
Upstream: fixed fail_timeout and max_fails > 1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5136
diff
changeset
|
578 best->checked = now; |
1d68b502088c
Upstream: fixed fail_timeout and max_fails > 1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5136
diff
changeset
|
579 } |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
580 |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
581 return best; |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
582 } |
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
583 |
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
584 |
884 | 585 void |
586 ngx_http_upstream_free_round_robin_peer(ngx_peer_connection_t *pc, void *data, | |
587 ngx_uint_t state) | |
588 { | |
589 ngx_http_upstream_rr_peer_data_t *rrp = data; | |
590 | |
591 time_t now; | |
592 ngx_http_upstream_rr_peer_t *peer; | |
593 | |
594 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0, | |
595 "free rr peer %ui %ui", pc->tries, state); | |
596 | |
597 /* TODO: NGX_PEER_KEEPALIVE */ | |
598 | |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
599 peer = rrp->current; |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
600 |
6114
4a640716f4e2
Upstream: fixed unlocked access to peer->conns.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
601 ngx_http_upstream_rr_peers_rlock(rrp->peers); |
4a640716f4e2
Upstream: fixed unlocked access to peer->conns.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
602 ngx_http_upstream_rr_peer_lock(rrp->peers, peer); |
4a640716f4e2
Upstream: fixed unlocked access to peer->conns.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
603 |
1378 | 604 if (rrp->peers->single) { |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
605 |
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
606 peer->conns--; |
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
607 |
6114
4a640716f4e2
Upstream: fixed unlocked access to peer->conns.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
608 ngx_http_upstream_rr_peer_unlock(rrp->peers, peer); |
4a640716f4e2
Upstream: fixed unlocked access to peer->conns.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
609 ngx_http_upstream_rr_peers_unlock(rrp->peers); |
4a640716f4e2
Upstream: fixed unlocked access to peer->conns.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
610 |
884 | 611 pc->tries = 0; |
612 return; | |
613 } | |
614 | |
615 if (state & NGX_PEER_FAILED) { | |
616 now = ngx_time(); | |
617 | |
618 peer->fails++; | |
619 peer->accessed = now; | |
4207
4fc91bae6f83
Better recheck of dead upstream servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4011
diff
changeset
|
620 peer->checked = now; |
884 | 621 |
2204
70a2bcc7e307
fix divide by zero if max_fails=0
Igor Sysoev <igor@sysoev.ru>
parents:
2197
diff
changeset
|
622 if (peer->max_fails) { |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
623 peer->effective_weight -= peer->weight / peer->max_fails; |
6154
cca856715722
Upstream: report to error_log when max_fails is reached.
Ruslan Ermilov <ru@nginx.com>
parents:
6114
diff
changeset
|
624 |
cca856715722
Upstream: report to error_log when max_fails is reached.
Ruslan Ermilov <ru@nginx.com>
parents:
6114
diff
changeset
|
625 if (peer->fails >= peer->max_fails) { |
cca856715722
Upstream: report to error_log when max_fails is reached.
Ruslan Ermilov <ru@nginx.com>
parents:
6114
diff
changeset
|
626 ngx_log_error(NGX_LOG_WARN, pc->log, 0, |
cca856715722
Upstream: report to error_log when max_fails is reached.
Ruslan Ermilov <ru@nginx.com>
parents:
6114
diff
changeset
|
627 "upstream server temporarily disabled"); |
cca856715722
Upstream: report to error_log when max_fails is reached.
Ruslan Ermilov <ru@nginx.com>
parents:
6114
diff
changeset
|
628 } |
2204
70a2bcc7e307
fix divide by zero if max_fails=0
Igor Sysoev <igor@sysoev.ru>
parents:
2197
diff
changeset
|
629 } |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
630 |
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
631 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
632 "free rr peer failed: %p %i", |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
633 peer, peer->effective_weight); |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
634 |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
635 if (peer->effective_weight < 0) { |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
636 peer->effective_weight = 0; |
884 | 637 } |
638 | |
4207
4fc91bae6f83
Better recheck of dead upstream servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4011
diff
changeset
|
639 } else { |
4fc91bae6f83
Better recheck of dead upstream servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4011
diff
changeset
|
640 |
4fc91bae6f83
Better recheck of dead upstream servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4011
diff
changeset
|
641 /* mark peer live if check passed */ |
4fc91bae6f83
Better recheck of dead upstream servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4011
diff
changeset
|
642 |
4fc91bae6f83
Better recheck of dead upstream servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4011
diff
changeset
|
643 if (peer->accessed < peer->checked) { |
4fc91bae6f83
Better recheck of dead upstream servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4011
diff
changeset
|
644 peer->fails = 0; |
4fc91bae6f83
Better recheck of dead upstream servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4011
diff
changeset
|
645 } |
884 | 646 } |
647 | |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
648 peer->conns--; |
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
649 |
6102 | 650 ngx_http_upstream_rr_peer_unlock(rrp->peers, peer); |
651 ngx_http_upstream_rr_peers_unlock(rrp->peers); | |
652 | |
884 | 653 if (pc->tries) { |
654 pc->tries--; | |
655 } | |
656 } | |
657 | |
658 | |
659 #if (NGX_HTTP_SSL) | |
660 | |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
661 ngx_int_t |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
662 ngx_http_upstream_set_round_robin_peer_session(ngx_peer_connection_t *pc, |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
663 void *data) |
884 | 664 { |
665 ngx_http_upstream_rr_peer_data_t *rrp = data; | |
666 | |
6103
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
667 ngx_int_t rc; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
668 ngx_ssl_session_t *ssl_session; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
669 ngx_http_upstream_rr_peer_t *peer; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
670 #if (NGX_HTTP_UPSTREAM_ZONE) |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
671 int len; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
672 #if OPENSSL_VERSION_NUMBER >= 0x0090707fL |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
673 const |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
674 #endif |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
675 u_char *p; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
676 ngx_http_upstream_rr_peers_t *peers; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
677 u_char buf[NGX_SSL_MAX_SESSION_SIZE]; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
678 #endif |
884 | 679 |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
680 peer = rrp->current; |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
681 |
6103
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
682 #if (NGX_HTTP_UPSTREAM_ZONE) |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
683 peers = rrp->peers; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
684 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
685 if (peers->shpool) { |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
686 ngx_http_upstream_rr_peers_rlock(peers); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
687 ngx_http_upstream_rr_peer_lock(peers, peer); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
688 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
689 if (peer->ssl_session == NULL) { |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
690 ngx_http_upstream_rr_peer_unlock(peers, peer); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
691 ngx_http_upstream_rr_peers_unlock(peers); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
692 return NGX_OK; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
693 } |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
694 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
695 len = peer->ssl_session_len; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
696 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
697 ngx_memcpy(buf, peer->ssl_session, len); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
698 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
699 ngx_http_upstream_rr_peer_unlock(peers, peer); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
700 ngx_http_upstream_rr_peers_unlock(peers); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
701 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
702 p = buf; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
703 ssl_session = d2i_SSL_SESSION(NULL, &p, len); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
704 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
705 rc = ngx_ssl_set_session(pc->connection, ssl_session); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
706 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
707 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
708 "set session: %p", ssl_session); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
709 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
710 ngx_ssl_free_session(ssl_session); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
711 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
712 return rc; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
713 } |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
714 #endif |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
715 |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
716 ssl_session = peer->ssl_session; |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
717 |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
718 rc = ngx_ssl_set_session(pc->connection, ssl_session); |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
719 |
5756
5b7276408565
SSL: stop accessing SSL_SESSION's fields directly.
Piotr Sikora <piotr@cloudflare.com>
parents:
5720
diff
changeset
|
720 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
5b7276408565
SSL: stop accessing SSL_SESSION's fields directly.
Piotr Sikora <piotr@cloudflare.com>
parents:
5720
diff
changeset
|
721 "set session: %p", ssl_session); |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
722 |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
723 return rc; |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
724 } |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
725 |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
726 |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
727 void |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
728 ngx_http_upstream_save_round_robin_peer_session(ngx_peer_connection_t *pc, |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
729 void *data) |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
730 { |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
731 ngx_http_upstream_rr_peer_data_t *rrp = data; |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
732 |
6103
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
733 ngx_ssl_session_t *old_ssl_session, *ssl_session; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
734 ngx_http_upstream_rr_peer_t *peer; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
735 #if (NGX_HTTP_UPSTREAM_ZONE) |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
736 int len; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
737 u_char *p; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
738 ngx_http_upstream_rr_peers_t *peers; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
739 u_char buf[NGX_SSL_MAX_SESSION_SIZE]; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
740 #endif |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
741 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
742 #if (NGX_HTTP_UPSTREAM_ZONE) |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
743 peers = rrp->peers; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
744 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
745 if (peers->shpool) { |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
746 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
747 ssl_session = SSL_get0_session(pc->connection->ssl->connection); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
748 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
749 if (ssl_session == NULL) { |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
750 return; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
751 } |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
752 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
753 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
754 "save session: %p", ssl_session); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
755 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
756 len = i2d_SSL_SESSION(ssl_session, NULL); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
757 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
758 /* do not cache too big session */ |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
759 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
760 if (len > NGX_SSL_MAX_SESSION_SIZE) { |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
761 return; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
762 } |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
763 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
764 p = buf; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
765 (void) i2d_SSL_SESSION(ssl_session, &p); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
766 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
767 peer = rrp->current; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
768 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
769 ngx_http_upstream_rr_peers_rlock(peers); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
770 ngx_http_upstream_rr_peer_lock(peers, peer); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
771 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
772 if (len > peer->ssl_session_len) { |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
773 ngx_shmtx_lock(&peers->shpool->mutex); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
774 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
775 if (peer->ssl_session) { |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
776 ngx_slab_free_locked(peers->shpool, peer->ssl_session); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
777 } |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
778 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
779 peer->ssl_session = ngx_slab_alloc_locked(peers->shpool, len); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
780 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
781 ngx_shmtx_unlock(&peers->shpool->mutex); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
782 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
783 if (peer->ssl_session == NULL) { |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
784 peer->ssl_session_len = 0; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
785 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
786 ngx_http_upstream_rr_peer_unlock(peers, peer); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
787 ngx_http_upstream_rr_peers_unlock(peers); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
788 return; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
789 } |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
790 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
791 peer->ssl_session_len = len; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
792 } |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
793 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
794 ngx_memcpy(peer->ssl_session, buf, len); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
795 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
796 ngx_http_upstream_rr_peer_unlock(peers, peer); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
797 ngx_http_upstream_rr_peers_unlock(peers); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
798 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
799 return; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
800 } |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
801 #endif |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
802 |
884 | 803 ssl_session = ngx_ssl_get_session(pc->connection); |
804 | |
805 if (ssl_session == NULL) { | |
806 return; | |
807 } | |
808 | |
5756
5b7276408565
SSL: stop accessing SSL_SESSION's fields directly.
Piotr Sikora <piotr@cloudflare.com>
parents:
5720
diff
changeset
|
809 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
5b7276408565
SSL: stop accessing SSL_SESSION's fields directly.
Piotr Sikora <piotr@cloudflare.com>
parents:
5720
diff
changeset
|
810 "save session: %p", ssl_session); |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
811 |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
812 peer = rrp->current; |
884 | 813 |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
814 old_ssl_session = peer->ssl_session; |
884 | 815 peer->ssl_session = ssl_session; |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
816 |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
817 if (old_ssl_session) { |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
818 |
5756
5b7276408565
SSL: stop accessing SSL_SESSION's fields directly.
Piotr Sikora <piotr@cloudflare.com>
parents:
5720
diff
changeset
|
819 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
5b7276408565
SSL: stop accessing SSL_SESSION's fields directly.
Piotr Sikora <piotr@cloudflare.com>
parents:
5720
diff
changeset
|
820 "old session: %p", old_ssl_session); |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
821 |
884 | 822 /* TODO: may block */ |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
823 |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
824 ngx_ssl_free_session(old_ssl_session); |
884 | 825 } |
826 } | |
827 | |
3964
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
828 |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
829 static ngx_int_t |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
830 ngx_http_upstream_empty_set_session(ngx_peer_connection_t *pc, void *data) |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
831 { |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
832 return NGX_OK; |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
833 } |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
834 |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
835 |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
836 static void |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
837 ngx_http_upstream_empty_save_session(ngx_peer_connection_t *pc, void *data) |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
838 { |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
839 return; |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
840 } |
ff127ba3b091
do not try to reuse and save a SSL session for a peer created on the fly
Igor Sysoev <igor@sysoev.ru>
parents:
2422
diff
changeset
|
841 |
884 | 842 #endif |