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