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