Mercurial > hg > nginx-quic
annotate src/http/ngx_http_upstream_round_robin.c @ 6133:af7eba90645d
Win32: shared memory base addresses and remapping.
Two mechanisms are implemented to make it possible to store pointers
in shared memory on Windows, in particular on Windows Vista and later
versions with ASLR:
- The ngx_shm_remap() function added to allow remapping of a shared memory
zone to the address originally used for it in the master process. While
important, it doesn't solve the problem by itself as in many cases it's
not possible to use the address because of conflicts with other
allocations.
- We now create mappings at the same address in all processes by starting
mappings at predefined addresses normally unused by newborn processes.
These two mechanisms combined allow to use shared memory on Windows
almost without problems, including reloads.
Based on the patch by Sergey Brester:
http://mailman.nginx.org/pipermail/nginx-devel/2015-April/006836.html
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 27 Apr 2015 18:25:42 +0300 |
parents | 4a640716f4e2 |
children | cca856715722 |
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); |
2422
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2204
diff
changeset
|
357 |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
358 switch (sockaddr->sa_family) { |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
359 #if (NGX_HAVE_INET6) |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
360 case AF_INET6: |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
361 ((struct sockaddr_in6 *) sockaddr)->sin6_port = htons(ur->port); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
362 break; |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
363 #endif |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
364 default: /* AF_INET */ |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
365 ((struct sockaddr_in *) sockaddr)->sin_port = htons(ur->port); |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
366 } |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
367 |
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
368 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
|
369 if (p == NULL) { |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2204
diff
changeset
|
370 return NGX_ERROR; |
7af1e5fe102c
variable support for unix sockets in fastcgi_pass and proxy_pass
Igor Sysoev <igor@sysoev.ru>
parents:
2204
diff
changeset
|
371 } |
1658 | 372 |
5475
07dd5bd222ac
Changed resolver API to use ngx_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
5454
diff
changeset
|
373 len = ngx_sock_ntop(sockaddr, socklen, p, NGX_SOCKADDR_STRLEN, 1); |
1658 | 374 |
5720
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
375 peer[i].sockaddr = sockaddr; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
376 peer[i].socklen = socklen; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
377 peer[i].name.len = len; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
378 peer[i].name.data = p; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
379 peer[i].weight = 1; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
380 peer[i].effective_weight = 1; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
381 peer[i].current_weight = 0; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
382 peer[i].max_fails = 1; |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
383 peer[i].fail_timeout = 10; |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
384 *peerp = &peer[i]; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
385 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
|
386 } |
1658 | 387 } |
388 | |
389 rrp->peers = peers; | |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
390 rrp->current = NULL; |
1658 | 391 |
392 if (rrp->peers->number <= 8 * sizeof(uintptr_t)) { | |
393 rrp->tried = &rrp->data; | |
394 rrp->data = 0; | |
395 | |
396 } else { | |
397 n = (rrp->peers->number + (8 * sizeof(uintptr_t) - 1)) | |
398 / (8 * sizeof(uintptr_t)); | |
399 | |
400 rrp->tried = ngx_pcalloc(r->pool, n * sizeof(uintptr_t)); | |
401 if (rrp->tried == NULL) { | |
402 return NGX_ERROR; | |
403 } | |
404 } | |
405 | |
406 r->upstream->peer.get = ngx_http_upstream_get_round_robin_peer; | |
407 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
|
408 r->upstream->peer.tries = ngx_http_upstream_tries(rrp->peers); |
1658 | 409 #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
|
410 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
|
411 r->upstream->peer.save_session = ngx_http_upstream_empty_save_session; |
1658 | 412 #endif |
413 | |
414 return NGX_OK; | |
415 } | |
416 | |
417 | |
418 ngx_int_t | |
884 | 419 ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, void *data) |
420 { | |
421 ngx_http_upstream_rr_peer_data_t *rrp = data; | |
422 | |
1378 | 423 ngx_int_t rc; |
424 ngx_uint_t i, n; | |
425 ngx_http_upstream_rr_peer_t *peer; | |
426 ngx_http_upstream_rr_peers_t *peers; | |
884 | 427 |
428 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, | |
429 "get rr peer, try: %ui", pc->tries); | |
430 | |
431 pc->cached = 0; | |
432 pc->connection = NULL; | |
433 | |
5720
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
434 peers = rrp->peers; |
6102 | 435 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
|
436 |
ab540dd44528
Upstream: simplified some code that accesses peers.
Ruslan Ermilov <ru@nginx.com>
parents:
5717
diff
changeset
|
437 if (peers->single) { |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
438 peer = peers->peer; |
884 | 439 |
4914
dcb853acae97
Upstream: honor the "down" flag for a single server.
Ruslan Ermilov <ru@nginx.com>
parents:
4655
diff
changeset
|
440 if (peer->down) { |
dcb853acae97
Upstream: honor the "down" flag for a single server.
Ruslan Ermilov <ru@nginx.com>
parents:
4655
diff
changeset
|
441 goto failed; |
dcb853acae97
Upstream: honor the "down" flag for a single server.
Ruslan Ermilov <ru@nginx.com>
parents:
4655
diff
changeset
|
442 } |
dcb853acae97
Upstream: honor the "down" flag for a single server.
Ruslan Ermilov <ru@nginx.com>
parents:
4655
diff
changeset
|
443 |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
444 rrp->current = peer; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
445 |
884 | 446 } else { |
447 | |
448 /* there are several peers */ | |
449 | |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
450 peer = ngx_http_upstream_get_peer(rrp); |
884 | 451 |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
452 if (peer == NULL) { |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
453 goto failed; |
884 | 454 } |
455 | |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
456 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
|
457 "get rr peer, current: %p %i", |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
458 peer, peer->current_weight); |
884 | 459 } |
460 | |
461 pc->sockaddr = peer->sockaddr; | |
462 pc->socklen = peer->socklen; | |
463 pc->name = &peer->name; | |
464 | |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
465 peer->conns++; |
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
466 |
6102 | 467 ngx_http_upstream_rr_peers_unlock(peers); |
884 | 468 |
469 return NGX_OK; | |
470 | |
471 failed: | |
472 | |
1378 | 473 if (peers->next) { |
474 | |
475 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0, "backup servers"); | |
476 | |
477 rrp->peers = peers->next; | |
478 | |
4991
a384c60d55f3
Upstream: fixed state resetting when switching to backup servers.
Valentin Bartenev <vbart@nginx.com>
parents:
4914
diff
changeset
|
479 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
|
480 / (8 * sizeof(uintptr_t)); |
a384c60d55f3
Upstream: fixed state resetting when switching to backup servers.
Valentin Bartenev <vbart@nginx.com>
parents:
4914
diff
changeset
|
481 |
1389 | 482 for (i = 0; i < n; i++) { |
1378 | 483 rrp->tried[i] = 0; |
484 } | |
485 | |
6102 | 486 ngx_http_upstream_rr_peers_unlock(peers); |
487 | |
1378 | 488 rc = ngx_http_upstream_get_round_robin_peer(pc, rrp); |
489 | |
490 if (rc != NGX_BUSY) { | |
491 return rc; | |
492 } | |
493 | |
6102 | 494 ngx_http_upstream_rr_peers_wlock(peers); |
1378 | 495 } |
496 | |
884 | 497 /* all peers failed, mark them as live for quick recovery */ |
498 | |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
499 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
|
500 peer->fails = 0; |
884 | 501 } |
502 | |
6102 | 503 ngx_http_upstream_rr_peers_unlock(peers); |
884 | 504 |
1378 | 505 pc->name = peers->name; |
884 | 506 |
507 return NGX_BUSY; | |
508 } | |
509 | |
510 | |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
511 static ngx_http_upstream_rr_peer_t * |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
512 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
|
513 { |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
514 time_t now; |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
515 uintptr_t m; |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
516 ngx_int_t total; |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
517 ngx_uint_t i, n, p; |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
518 ngx_http_upstream_rr_peer_t *peer, *best; |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
519 |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
520 now = ngx_time(); |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
521 |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
522 best = NULL; |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
523 total = 0; |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
524 |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
525 #if (NGX_SUPPRESS_WARN) |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
526 p = 0; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
527 #endif |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
528 |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
529 for (peer = rrp->peers->peer, i = 0; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
530 peer; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
531 peer = peer->next, i++) |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
532 { |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
533 |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
534 n = i / (8 * sizeof(uintptr_t)); |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
535 m = (uintptr_t) 1 << i % (8 * sizeof(uintptr_t)); |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
536 |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
537 if (rrp->tried[n] & m) { |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
538 continue; |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
539 } |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
540 |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
541 if (peer->down) { |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
542 continue; |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
543 } |
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
544 |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
545 if (peer->max_fails |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
546 && peer->fails >= peer->max_fails |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
547 && now - peer->checked <= peer->fail_timeout) |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
548 { |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
549 continue; |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
550 } |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
551 |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
552 peer->current_weight += peer->effective_weight; |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
553 total += peer->effective_weight; |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
554 |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
555 if (peer->effective_weight < peer->weight) { |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
556 peer->effective_weight++; |
4010
74a93d3fdd85
Fixing cpu hog with all upstream servers marked "down".
Maxim Dounin <mdounin@mdounin.ru>
parents:
3964
diff
changeset
|
557 } |
74a93d3fdd85
Fixing cpu hog with all upstream servers marked "down".
Maxim Dounin <mdounin@mdounin.ru>
parents:
3964
diff
changeset
|
558 |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
559 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
|
560 best = peer; |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
561 p = i; |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
562 } |
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
563 } |
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 if (best == NULL) { |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
566 return NULL; |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
567 } |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
568 |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
569 rrp->current = best; |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
570 |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
571 n = p / (8 * sizeof(uintptr_t)); |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
572 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
|
573 |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
574 rrp->tried[n] |= m; |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
575 |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
576 best->current_weight -= total; |
5220
1d68b502088c
Upstream: fixed fail_timeout and max_fails > 1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5136
diff
changeset
|
577 |
1d68b502088c
Upstream: fixed fail_timeout and max_fails > 1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5136
diff
changeset
|
578 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
|
579 best->checked = now; |
1d68b502088c
Upstream: fixed fail_timeout and max_fails > 1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5136
diff
changeset
|
580 } |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
581 |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
582 return best; |
1344
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 |
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
585 |
884 | 586 void |
587 ngx_http_upstream_free_round_robin_peer(ngx_peer_connection_t *pc, void *data, | |
588 ngx_uint_t state) | |
589 { | |
590 ngx_http_upstream_rr_peer_data_t *rrp = data; | |
591 | |
592 time_t now; | |
593 ngx_http_upstream_rr_peer_t *peer; | |
594 | |
595 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0, | |
596 "free rr peer %ui %ui", pc->tries, state); | |
597 | |
598 /* TODO: NGX_PEER_KEEPALIVE */ | |
599 | |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
600 peer = rrp->current; |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
601 |
6114
4a640716f4e2
Upstream: fixed unlocked access to peer->conns.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
602 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
|
603 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
|
604 |
1378 | 605 if (rrp->peers->single) { |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
606 |
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
607 peer->conns--; |
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
608 |
6114
4a640716f4e2
Upstream: fixed unlocked access to peer->conns.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
609 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
|
610 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
|
611 |
884 | 612 pc->tries = 0; |
613 return; | |
614 } | |
615 | |
616 if (state & NGX_PEER_FAILED) { | |
617 now = ngx_time(); | |
618 | |
619 peer->fails++; | |
620 peer->accessed = now; | |
4207
4fc91bae6f83
Better recheck of dead upstream servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4011
diff
changeset
|
621 peer->checked = now; |
884 | 622 |
2204
70a2bcc7e307
fix divide by zero if max_fails=0
Igor Sysoev <igor@sysoev.ru>
parents:
2197
diff
changeset
|
623 if (peer->max_fails) { |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
624 peer->effective_weight -= peer->weight / peer->max_fails; |
2204
70a2bcc7e307
fix divide by zero if max_fails=0
Igor Sysoev <igor@sysoev.ru>
parents:
2197
diff
changeset
|
625 } |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
626 |
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
627 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
|
628 "free rr peer failed: %p %i", |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
629 peer, peer->effective_weight); |
1344
8f5b5641966c
fair upstream weight balancer
Igor Sysoev <igor@sysoev.ru>
parents:
1284
diff
changeset
|
630 |
4621
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
631 if (peer->effective_weight < 0) { |
c90801720a0c
Upstream: smooth weighted round-robin balancing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4569
diff
changeset
|
632 peer->effective_weight = 0; |
884 | 633 } |
634 | |
4207
4fc91bae6f83
Better recheck of dead upstream servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4011
diff
changeset
|
635 } else { |
4fc91bae6f83
Better recheck of dead upstream servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4011
diff
changeset
|
636 |
4fc91bae6f83
Better recheck of dead upstream servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4011
diff
changeset
|
637 /* mark peer live if check passed */ |
4fc91bae6f83
Better recheck of dead upstream servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4011
diff
changeset
|
638 |
4fc91bae6f83
Better recheck of dead upstream servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4011
diff
changeset
|
639 if (peer->accessed < peer->checked) { |
4fc91bae6f83
Better recheck of dead upstream servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4011
diff
changeset
|
640 peer->fails = 0; |
4fc91bae6f83
Better recheck of dead upstream servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4011
diff
changeset
|
641 } |
884 | 642 } |
643 | |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
644 peer->conns--; |
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
645 |
6102 | 646 ngx_http_upstream_rr_peer_unlock(rrp->peers, peer); |
647 ngx_http_upstream_rr_peers_unlock(rrp->peers); | |
648 | |
884 | 649 if (pc->tries) { |
650 pc->tries--; | |
651 } | |
652 } | |
653 | |
654 | |
655 #if (NGX_HTTP_SSL) | |
656 | |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
657 ngx_int_t |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
658 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
|
659 void *data) |
884 | 660 { |
661 ngx_http_upstream_rr_peer_data_t *rrp = data; | |
662 | |
6103
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
663 ngx_int_t rc; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
664 ngx_ssl_session_t *ssl_session; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
665 ngx_http_upstream_rr_peer_t *peer; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
666 #if (NGX_HTTP_UPSTREAM_ZONE) |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
667 int len; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
668 #if OPENSSL_VERSION_NUMBER >= 0x0090707fL |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
669 const |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
670 #endif |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
671 u_char *p; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
672 ngx_http_upstream_rr_peers_t *peers; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
673 u_char buf[NGX_SSL_MAX_SESSION_SIZE]; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
674 #endif |
884 | 675 |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
676 peer = rrp->current; |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
677 |
6103
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
678 #if (NGX_HTTP_UPSTREAM_ZONE) |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
679 peers = rrp->peers; |
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 (peers->shpool) { |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
682 ngx_http_upstream_rr_peers_rlock(peers); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
683 ngx_http_upstream_rr_peer_lock(peers, peer); |
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 (peer->ssl_session == NULL) { |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
686 ngx_http_upstream_rr_peer_unlock(peers, peer); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
687 ngx_http_upstream_rr_peers_unlock(peers); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
688 return NGX_OK; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
689 } |
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 len = peer->ssl_session_len; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
692 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
693 ngx_memcpy(buf, peer->ssl_session, len); |
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 ngx_http_upstream_rr_peer_unlock(peers, peer); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
696 ngx_http_upstream_rr_peers_unlock(peers); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
697 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
698 p = buf; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
699 ssl_session = d2i_SSL_SESSION(NULL, &p, len); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
700 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
701 rc = ngx_ssl_set_session(pc->connection, ssl_session); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
702 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
703 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
704 "set session: %p", ssl_session); |
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 ngx_ssl_free_session(ssl_session); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
707 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
708 return rc; |
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 #endif |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
711 |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
712 ssl_session = peer->ssl_session; |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
713 |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
714 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
|
715 |
5756
5b7276408565
SSL: stop accessing SSL_SESSION's fields directly.
Piotr Sikora <piotr@cloudflare.com>
parents:
5720
diff
changeset
|
716 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
|
717 "set session: %p", ssl_session); |
1284
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 return rc; |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
720 } |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
721 |
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 void |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
724 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
|
725 void *data) |
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 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
|
728 |
6103
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
729 ngx_ssl_session_t *old_ssl_session, *ssl_session; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
730 ngx_http_upstream_rr_peer_t *peer; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
731 #if (NGX_HTTP_UPSTREAM_ZONE) |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
732 int len; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
733 u_char *p; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
734 ngx_http_upstream_rr_peers_t *peers; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
735 u_char buf[NGX_SSL_MAX_SESSION_SIZE]; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
736 #endif |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
737 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
738 #if (NGX_HTTP_UPSTREAM_ZONE) |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
739 peers = rrp->peers; |
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 (peers->shpool) { |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
742 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
743 ssl_session = SSL_get0_session(pc->connection->ssl->connection); |
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 (ssl_session == NULL) { |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
746 return; |
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 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
749 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
750 "save session: %p", ssl_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 len = i2d_SSL_SESSION(ssl_session, NULL); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
753 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
754 /* do not cache too big 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 if (len > NGX_SSL_MAX_SESSION_SIZE) { |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
757 return; |
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 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
760 p = buf; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
761 (void) i2d_SSL_SESSION(ssl_session, &p); |
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 peer = rrp->current; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
764 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
765 ngx_http_upstream_rr_peers_rlock(peers); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
766 ngx_http_upstream_rr_peer_lock(peers, peer); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
767 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
768 if (len > peer->ssl_session_len) { |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
769 ngx_shmtx_lock(&peers->shpool->mutex); |
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 if (peer->ssl_session) { |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
772 ngx_slab_free_locked(peers->shpool, peer->ssl_session); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
773 } |
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 peer->ssl_session = ngx_slab_alloc_locked(peers->shpool, len); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
776 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
777 ngx_shmtx_unlock(&peers->shpool->mutex); |
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 if (peer->ssl_session == NULL) { |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
780 peer->ssl_session_len = 0; |
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 ngx_http_upstream_rr_peer_unlock(peers, peer); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
783 ngx_http_upstream_rr_peers_unlock(peers); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
784 return; |
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 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
787 peer->ssl_session_len = len; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
788 } |
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 ngx_memcpy(peer->ssl_session, buf, len); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
791 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
792 ngx_http_upstream_rr_peer_unlock(peers, peer); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
793 ngx_http_upstream_rr_peers_unlock(peers); |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
794 |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
795 return; |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
796 } |
79ddb0bdb273
Upstream: the "zone" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
6102
diff
changeset
|
797 #endif |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
798 |
884 | 799 ssl_session = ngx_ssl_get_session(pc->connection); |
800 | |
801 if (ssl_session == NULL) { | |
802 return; | |
803 } | |
804 | |
5756
5b7276408565
SSL: stop accessing SSL_SESSION's fields directly.
Piotr Sikora <piotr@cloudflare.com>
parents:
5720
diff
changeset
|
805 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
|
806 "save session: %p", ssl_session); |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
807 |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
808 peer = rrp->current; |
884 | 809 |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
810 old_ssl_session = peer->ssl_session; |
884 | 811 peer->ssl_session = ssl_session; |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
812 |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
813 if (old_ssl_session) { |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
814 |
5756
5b7276408565
SSL: stop accessing SSL_SESSION's fields directly.
Piotr Sikora <piotr@cloudflare.com>
parents:
5720
diff
changeset
|
815 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
|
816 "old session: %p", old_ssl_session); |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
817 |
884 | 818 /* TODO: may block */ |
1284
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
819 |
be2b895d31e0
fix segfault when session was freed twice
Igor Sysoev <igor@sysoev.ru>
parents:
1206
diff
changeset
|
820 ngx_ssl_free_session(old_ssl_session); |
884 | 821 } |
822 } | |
823 | |
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
|
824 |
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 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
|
826 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
|
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 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
|
829 } |
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 |
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 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
|
833 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
|
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 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
|
836 } |
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 |
884 | 838 #endif |