nginxtra 1.8.1.12 → 1.10.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. checksums.yaml +4 -4
  2. data/bin/nginxtra +1 -1
  3. data/bin/nginxtra_rails +1 -1
  4. data/lib/nginxtra/version.rb +1 -1
  5. data/vendor/nginx/CHANGES +363 -25
  6. data/vendor/nginx/CHANGES.ru +365 -21
  7. data/vendor/nginx/LICENSE +2 -2
  8. data/vendor/nginx/auto/cc/conf +32 -0
  9. data/vendor/nginx/auto/cc/gcc +1 -1
  10. data/vendor/nginx/auto/cc/icc +2 -2
  11. data/vendor/nginx/auto/cc/msvc +29 -8
  12. data/vendor/nginx/auto/cc/name +2 -25
  13. data/vendor/nginx/auto/cc/sunc +3 -0
  14. data/vendor/nginx/auto/endianness +7 -2
  15. data/vendor/nginx/auto/install +60 -26
  16. data/vendor/nginx/auto/lib/conf +4 -4
  17. data/vendor/nginx/auto/lib/geoip/conf +6 -1
  18. data/vendor/nginx/auto/lib/libgd/conf +6 -1
  19. data/vendor/nginx/auto/lib/libxslt/conf +11 -2
  20. data/vendor/nginx/auto/lib/make +1 -1
  21. data/vendor/nginx/auto/lib/md5/conf +2 -2
  22. data/vendor/nginx/auto/lib/md5/make +2 -2
  23. data/vendor/nginx/auto/lib/openssl/conf +52 -3
  24. data/vendor/nginx/auto/lib/openssl/make +1 -1
  25. data/vendor/nginx/auto/lib/pcre/conf +2 -2
  26. data/vendor/nginx/auto/lib/pcre/make +2 -2
  27. data/vendor/nginx/auto/lib/perl/conf +6 -3
  28. data/vendor/nginx/auto/lib/perl/make +4 -1
  29. data/vendor/nginx/auto/lib/sha1/conf +2 -2
  30. data/vendor/nginx/auto/lib/sha1/make +2 -2
  31. data/vendor/nginx/auto/lib/zlib/conf +2 -2
  32. data/vendor/nginx/auto/lib/zlib/make +2 -2
  33. data/vendor/nginx/auto/make +281 -16
  34. data/vendor/nginx/auto/module +122 -0
  35. data/vendor/nginx/auto/modules +909 -178
  36. data/vendor/nginx/auto/options +81 -19
  37. data/vendor/nginx/auto/os/conf +9 -0
  38. data/vendor/nginx/auto/os/darwin +3 -0
  39. data/vendor/nginx/auto/os/freebsd +0 -20
  40. data/vendor/nginx/auto/os/linux +0 -12
  41. data/vendor/nginx/auto/os/win32 +5 -1
  42. data/vendor/nginx/auto/sources +11 -311
  43. data/vendor/nginx/auto/summary +1 -0
  44. data/vendor/nginx/auto/types/sizeof +5 -3
  45. data/vendor/nginx/auto/types/typedef +9 -4
  46. data/vendor/nginx/auto/types/uintptr_t +7 -2
  47. data/vendor/nginx/auto/unix +72 -12
  48. data/vendor/nginx/conf/fastcgi.conf +1 -0
  49. data/vendor/nginx/conf/fastcgi_params +1 -0
  50. data/vendor/nginx/conf/scgi_params +1 -0
  51. data/vendor/nginx/conf/uwsgi_params +1 -0
  52. data/vendor/nginx/configure +1 -1
  53. data/vendor/nginx/contrib/vim/syntax/nginx.vim +2 -2
  54. data/vendor/nginx/man/nginx.8 +6 -2
  55. data/vendor/nginx/src/core/nginx.c +281 -114
  56. data/vendor/nginx/src/core/nginx.h +2 -2
  57. data/vendor/nginx/src/core/ngx_conf_file.c +54 -13
  58. data/vendor/nginx/src/core/ngx_conf_file.h +8 -52
  59. data/vendor/nginx/src/core/ngx_config.h +0 -5
  60. data/vendor/nginx/src/core/ngx_connection.c +270 -37
  61. data/vendor/nginx/src/core/ngx_connection.h +35 -12
  62. data/vendor/nginx/src/core/ngx_core.h +4 -0
  63. data/vendor/nginx/src/core/ngx_crypt.c +2 -2
  64. data/vendor/nginx/src/core/ngx_cycle.c +72 -25
  65. data/vendor/nginx/src/core/ngx_cycle.h +28 -39
  66. data/vendor/nginx/src/core/ngx_file.c +14 -5
  67. data/vendor/nginx/src/core/ngx_file.h +2 -0
  68. data/vendor/nginx/src/core/ngx_hash.c +13 -1
  69. data/vendor/nginx/src/core/ngx_inet.c +20 -18
  70. data/vendor/nginx/src/core/ngx_log.c +12 -12
  71. data/vendor/nginx/src/core/ngx_log.h +13 -6
  72. data/vendor/nginx/src/core/ngx_module.c +360 -0
  73. data/vendor/nginx/src/core/ngx_module.h +307 -0
  74. data/vendor/nginx/src/core/ngx_open_file_cache.c +2 -2
  75. data/vendor/nginx/src/core/ngx_output_chain.c +8 -4
  76. data/vendor/nginx/src/core/ngx_palloc.c +42 -44
  77. data/vendor/nginx/src/{http/ngx_http_parse_time.c → core/ngx_parse_time.c} +2 -3
  78. data/vendor/nginx/src/core/ngx_parse_time.h +22 -0
  79. data/vendor/nginx/src/core/ngx_proxy_protocol.c +50 -1
  80. data/vendor/nginx/src/core/ngx_proxy_protocol.h +3 -1
  81. data/vendor/nginx/src/core/ngx_regex.c +1 -38
  82. data/vendor/nginx/src/core/ngx_resolver.c +1814 -320
  83. data/vendor/nginx/src/core/ngx_resolver.h +67 -10
  84. data/vendor/nginx/src/core/ngx_rwlock.c +120 -0
  85. data/vendor/nginx/src/core/ngx_rwlock.h +21 -0
  86. data/vendor/nginx/src/core/ngx_slab.c +6 -5
  87. data/vendor/nginx/src/core/ngx_string.c +1 -1
  88. data/vendor/nginx/src/core/ngx_syslog.c +11 -3
  89. data/vendor/nginx/src/core/ngx_syslog.h +2 -1
  90. data/vendor/nginx/src/core/ngx_thread_pool.c +4 -0
  91. data/vendor/nginx/src/core/ngx_times.c +2 -2
  92. data/vendor/nginx/src/event/modules/ngx_devpoll_module.c +3 -1
  93. data/vendor/nginx/src/event/modules/ngx_epoll_module.c +5 -2
  94. data/vendor/nginx/src/event/modules/ngx_eventport_module.c +5 -5
  95. data/vendor/nginx/src/event/modules/ngx_kqueue_module.c +15 -8
  96. data/vendor/nginx/src/event/modules/ngx_poll_module.c +0 -10
  97. data/vendor/nginx/src/event/modules/ngx_select_module.c +0 -10
  98. data/vendor/nginx/src/event/ngx_event.c +60 -103
  99. data/vendor/nginx/src/event/ngx_event.h +22 -26
  100. data/vendor/nginx/src/event/ngx_event_accept.c +414 -88
  101. data/vendor/nginx/src/event/ngx_event_connect.c +27 -18
  102. data/vendor/nginx/src/event/ngx_event_connect.h +1 -0
  103. data/vendor/nginx/src/event/ngx_event_openssl.c +65 -25
  104. data/vendor/nginx/src/event/ngx_event_openssl.h +17 -0
  105. data/vendor/nginx/src/event/ngx_event_openssl_stapling.c +73 -7
  106. data/vendor/nginx/src/event/ngx_event_pipe.c +85 -27
  107. data/vendor/nginx/src/event/ngx_event_pipe.h +10 -0
  108. data/vendor/nginx/src/http/modules/ngx_http_auth_basic_module.c +1 -1
  109. data/vendor/nginx/src/http/modules/ngx_http_auth_request_module.c +2 -2
  110. data/vendor/nginx/src/http/modules/ngx_http_chunked_filter_module.c +2 -2
  111. data/vendor/nginx/src/http/modules/ngx_http_dav_module.c +6 -6
  112. data/vendor/nginx/src/http/modules/ngx_http_fastcgi_module.c +17 -11
  113. data/vendor/nginx/src/http/modules/ngx_http_gzip_filter_module.c +2 -2
  114. data/vendor/nginx/src/http/modules/ngx_http_headers_filter_module.c +9 -9
  115. data/vendor/nginx/src/http/modules/ngx_http_image_filter_module.c +2 -2
  116. data/vendor/nginx/src/http/modules/ngx_http_limit_conn_module.c +2 -2
  117. data/vendor/nginx/src/http/modules/ngx_http_limit_req_module.c +0 -7
  118. data/vendor/nginx/src/http/modules/ngx_http_map_module.c +6 -6
  119. data/vendor/nginx/src/http/modules/ngx_http_memcached_module.c +2 -1
  120. data/vendor/nginx/src/http/modules/ngx_http_mp4_module.c +13 -13
  121. data/vendor/nginx/src/http/modules/ngx_http_not_modified_filter_module.c +2 -2
  122. data/vendor/nginx/src/http/modules/ngx_http_proxy_module.c +26 -21
  123. data/vendor/nginx/src/http/modules/ngx_http_random_index_module.c +1 -1
  124. data/vendor/nginx/src/http/modules/ngx_http_range_filter_module.c +26 -8
  125. data/vendor/nginx/src/http/modules/ngx_http_realip_module.c +73 -3
  126. data/vendor/nginx/src/http/modules/ngx_http_referer_module.c +1 -1
  127. data/vendor/nginx/src/http/modules/ngx_http_rewrite_module.c +6 -6
  128. data/vendor/nginx/src/http/modules/ngx_http_scgi_module.c +5 -3
  129. data/vendor/nginx/src/http/modules/ngx_http_slice_filter_module.c +526 -0
  130. data/vendor/nginx/src/http/modules/ngx_http_ssi_filter_module.c +7 -7
  131. data/vendor/nginx/src/http/modules/ngx_http_ssl_module.c +19 -16
  132. data/vendor/nginx/src/http/modules/ngx_http_static_module.c +1 -1
  133. data/vendor/nginx/src/http/modules/ngx_http_stub_status_module.c +1 -1
  134. data/vendor/nginx/src/http/modules/ngx_http_sub_filter_module.c +373 -173
  135. data/vendor/nginx/src/http/modules/ngx_http_upstream_hash_module.c +72 -46
  136. data/vendor/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +18 -30
  137. data/vendor/nginx/src/http/modules/ngx_http_upstream_keepalive_module.c +50 -39
  138. data/vendor/nginx/src/http/modules/ngx_http_upstream_least_conn_module.c +38 -129
  139. data/vendor/nginx/src/http/modules/ngx_http_upstream_zone_module.c +246 -0
  140. data/vendor/nginx/src/http/modules/ngx_http_uwsgi_module.c +6 -5
  141. data/vendor/nginx/src/http/modules/perl/nginx.xs +9 -9
  142. data/vendor/nginx/src/http/ngx_http.c +46 -43
  143. data/vendor/nginx/src/http/ngx_http.h +4 -9
  144. data/vendor/nginx/src/http/ngx_http_cache.h +4 -0
  145. data/vendor/nginx/src/http/ngx_http_copy_filter_module.c +13 -5
  146. data/vendor/nginx/src/http/ngx_http_core_module.c +92 -91
  147. data/vendor/nginx/src/http/ngx_http_core_module.h +12 -8
  148. data/vendor/nginx/src/http/ngx_http_file_cache.c +61 -10
  149. data/vendor/nginx/src/http/ngx_http_request.c +37 -50
  150. data/vendor/nginx/src/http/ngx_http_request.h +10 -15
  151. data/vendor/nginx/src/http/ngx_http_request_body.c +64 -88
  152. data/vendor/nginx/src/http/ngx_http_script.c +3 -3
  153. data/vendor/nginx/src/http/ngx_http_special_response.c +1 -4
  154. data/vendor/nginx/src/http/ngx_http_upstream.c +245 -109
  155. data/vendor/nginx/src/http/ngx_http_upstream.h +11 -5
  156. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.c +212 -65
  157. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.h +66 -5
  158. data/vendor/nginx/src/http/ngx_http_variables.c +28 -15
  159. data/vendor/nginx/src/http/ngx_http_write_filter_module.c +1 -1
  160. data/vendor/nginx/src/http/v2/ngx_http_v2.c +4349 -0
  161. data/vendor/nginx/src/http/v2/ngx_http_v2.h +337 -0
  162. data/vendor/nginx/src/http/v2/ngx_http_v2_filter_module.c +1391 -0
  163. data/vendor/nginx/src/http/v2/ngx_http_v2_huff_decode.c +2714 -0
  164. data/vendor/nginx/src/http/v2/ngx_http_v2_huff_encode.c +254 -0
  165. data/vendor/nginx/src/http/v2/ngx_http_v2_module.c +469 -0
  166. data/vendor/nginx/src/http/{ngx_http_spdy_module.h → v2/ngx_http_v2_module.h} +10 -9
  167. data/vendor/nginx/src/http/v2/ngx_http_v2_table.c +349 -0
  168. data/vendor/nginx/src/mail/ngx_mail.c +49 -82
  169. data/vendor/nginx/src/mail/ngx_mail.h +16 -23
  170. data/vendor/nginx/src/mail/ngx_mail_auth_http_module.c +1 -1
  171. data/vendor/nginx/src/mail/ngx_mail_core_module.c +60 -34
  172. data/vendor/nginx/src/mail/ngx_mail_handler.c +17 -12
  173. data/vendor/nginx/src/mail/ngx_mail_proxy_module.c +1 -14
  174. data/vendor/nginx/src/mail/ngx_mail_smtp_handler.c +1 -1
  175. data/vendor/nginx/src/mail/ngx_mail_ssl_module.c +5 -5
  176. data/vendor/nginx/src/os/unix/ngx_atomic.h +10 -10
  177. data/vendor/nginx/src/os/unix/ngx_channel.h +4 -4
  178. data/vendor/nginx/src/os/unix/ngx_darwin_config.h +2 -0
  179. data/vendor/nginx/src/os/unix/ngx_darwin_init.c +1 -0
  180. data/vendor/nginx/src/os/unix/ngx_dlopen.c +28 -0
  181. data/vendor/nginx/src/os/unix/ngx_dlopen.h +31 -0
  182. data/vendor/nginx/src/os/unix/ngx_errno.h +1 -0
  183. data/vendor/nginx/src/os/unix/ngx_file_aio_read.c +1 -1
  184. data/vendor/nginx/src/os/unix/ngx_files.c +313 -80
  185. data/vendor/nginx/src/os/unix/ngx_files.h +5 -2
  186. data/vendor/nginx/src/os/unix/ngx_freebsd_config.h +3 -1
  187. data/vendor/nginx/src/os/unix/ngx_freebsd_init.c +1 -0
  188. data/vendor/nginx/src/os/unix/ngx_freebsd_sendfile_chain.c +13 -0
  189. data/vendor/nginx/src/os/unix/ngx_linux.h +0 -2
  190. data/vendor/nginx/src/os/unix/ngx_linux_aio_read.c +1 -1
  191. data/vendor/nginx/src/os/unix/ngx_linux_config.h +2 -6
  192. data/vendor/nginx/src/os/unix/ngx_linux_init.c +1 -33
  193. data/vendor/nginx/src/os/unix/ngx_linux_sendfile_chain.c +55 -12
  194. data/vendor/nginx/src/os/unix/ngx_os.h +3 -9
  195. data/vendor/nginx/src/os/unix/ngx_posix_config.h +14 -1
  196. data/vendor/nginx/src/os/unix/ngx_posix_init.c +2 -1
  197. data/vendor/nginx/src/os/unix/ngx_process.c +1 -1
  198. data/vendor/nginx/src/os/unix/ngx_process_cycle.c +25 -51
  199. data/vendor/nginx/src/os/unix/ngx_process_cycle.h +1 -0
  200. data/vendor/nginx/src/os/unix/ngx_readv_chain.c +24 -28
  201. data/vendor/nginx/src/os/unix/ngx_recv.c +30 -79
  202. data/vendor/nginx/src/os/unix/ngx_send.c +1 -1
  203. data/vendor/nginx/src/os/unix/ngx_setaffinity.c +14 -30
  204. data/vendor/nginx/src/os/unix/ngx_setaffinity.h +15 -1
  205. data/vendor/nginx/src/os/unix/ngx_solaris_config.h +2 -0
  206. data/vendor/nginx/src/os/unix/ngx_solaris_init.c +1 -0
  207. data/vendor/nginx/src/os/unix/ngx_solaris_sendfilev_chain.c +23 -0
  208. data/vendor/nginx/src/os/unix/ngx_sunpro_amd64.il +3 -3
  209. data/vendor/nginx/src/os/unix/ngx_sunpro_x86.il +3 -3
  210. data/vendor/nginx/src/os/unix/ngx_udp_recv.c +5 -48
  211. data/vendor/nginx/src/os/unix/ngx_udp_send.c +56 -0
  212. data/vendor/nginx/src/stream/ngx_stream.c +564 -0
  213. data/vendor/nginx/src/stream/ngx_stream.h +212 -0
  214. data/vendor/nginx/src/stream/ngx_stream_access_module.c +451 -0
  215. data/vendor/nginx/src/stream/ngx_stream_core_module.c +562 -0
  216. data/vendor/nginx/src/stream/ngx_stream_handler.c +344 -0
  217. data/vendor/nginx/src/stream/ngx_stream_limit_conn_module.c +632 -0
  218. data/vendor/nginx/src/stream/ngx_stream_proxy_module.c +1674 -0
  219. data/vendor/nginx/src/stream/ngx_stream_ssl_module.c +460 -0
  220. data/vendor/nginx/src/stream/ngx_stream_ssl_module.h +49 -0
  221. data/vendor/nginx/src/stream/ngx_stream_upstream.c +464 -0
  222. data/vendor/nginx/src/stream/ngx_stream_upstream.h +107 -0
  223. data/vendor/nginx/src/stream/ngx_stream_upstream_hash_module.c +656 -0
  224. data/vendor/nginx/src/stream/ngx_stream_upstream_least_conn_module.c +307 -0
  225. data/vendor/nginx/src/stream/ngx_stream_upstream_round_robin.c +702 -0
  226. data/vendor/nginx/src/stream/ngx_stream_upstream_round_robin.h +139 -0
  227. data/vendor/nginx/src/stream/ngx_stream_upstream_zone_module.c +242 -0
  228. metadata +39 -15
  229. data/vendor/nginx/src/event/modules/ngx_aio_module.c +0 -171
  230. data/vendor/nginx/src/event/modules/ngx_rtsig_module.c +0 -735
  231. data/vendor/nginx/src/http/ngx_http_spdy.c +0 -3701
  232. data/vendor/nginx/src/http/ngx_http_spdy.h +0 -261
  233. data/vendor/nginx/src/http/ngx_http_spdy_filter_module.c +0 -1222
  234. data/vendor/nginx/src/http/ngx_http_spdy_module.c +0 -408
  235. data/vendor/nginx/src/os/unix/ngx_aio_read.c +0 -109
  236. data/vendor/nginx/src/os/unix/ngx_aio_read_chain.c +0 -78
  237. data/vendor/nginx/src/os/unix/ngx_aio_write.c +0 -109
  238. data/vendor/nginx/src/os/unix/ngx_aio_write_chain.c +0 -100
@@ -29,6 +29,7 @@
29
29
  #define NGX_HTTP_UPSTREAM_FT_UPDATING 0x00000400
30
30
  #define NGX_HTTP_UPSTREAM_FT_BUSY_LOCK 0x00000800
31
31
  #define NGX_HTTP_UPSTREAM_FT_MAX_WAITING 0x00001000
32
+ #define NGX_HTTP_UPSTREAM_FT_NON_IDEMPOTENT 0x00002000
32
33
  #define NGX_HTTP_UPSTREAM_FT_NOLIVE 0x40000000
33
34
  #define NGX_HTTP_UPSTREAM_FT_OFF 0x80000000
34
35
 
@@ -58,10 +59,9 @@ typedef struct {
58
59
  ngx_uint_t bl_state;
59
60
 
60
61
  ngx_uint_t status;
61
- time_t response_sec;
62
- ngx_uint_t response_msec;
63
- time_t header_sec;
64
- ngx_uint_t header_msec;
62
+ ngx_msec_t response_time;
63
+ ngx_msec_t connect_time;
64
+ ngx_msec_t header_time;
65
65
  off_t response_length;
66
66
 
67
67
  ngx_str_t *peer;
@@ -123,6 +123,10 @@ struct ngx_http_upstream_srv_conf_s {
123
123
  in_port_t port;
124
124
  in_port_t default_port;
125
125
  ngx_uint_t no_port; /* unsigned no_port:1 */
126
+
127
+ #if (NGX_HTTP_UPSTREAM_ZONE)
128
+ ngx_shm_zone_t *shm_zone;
129
+ #endif
126
130
  };
127
131
 
128
132
 
@@ -190,6 +194,7 @@ typedef struct {
190
194
  ngx_msec_t cache_lock_age;
191
195
 
192
196
  ngx_flag_t cache_revalidate;
197
+ ngx_flag_t cache_convert_head;
193
198
 
194
199
  ngx_array_t *cache_valid;
195
200
  ngx_array_t *cache_bypass;
@@ -277,7 +282,7 @@ typedef struct {
277
282
  ngx_uint_t no_port; /* unsigned no_port:1 */
278
283
 
279
284
  ngx_uint_t naddrs;
280
- ngx_addr_t *addrs;
285
+ ngx_resolver_addr_t *addrs;
281
286
 
282
287
  struct sockaddr *sockaddr;
283
288
  socklen_t socklen;
@@ -366,6 +371,7 @@ struct ngx_http_upstream_s {
366
371
  unsigned upgrade:1;
367
372
 
368
373
  unsigned request_sent:1;
374
+ unsigned request_body_sent:1;
369
375
  unsigned header_sent:1;
370
376
  };
371
377
 
@@ -34,7 +34,7 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
34
34
  ngx_url_t u;
35
35
  ngx_uint_t i, j, n, w;
36
36
  ngx_http_upstream_server_t *server;
37
- ngx_http_upstream_rr_peer_t *peer;
37
+ ngx_http_upstream_rr_peer_t *peer, **peerp;
38
38
  ngx_http_upstream_rr_peers_t *peers, *backup;
39
39
 
40
40
  us->peer.init = ngx_http_upstream_init_round_robin_peer;
@@ -61,12 +61,16 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
61
61
  return NGX_ERROR;
62
62
  }
63
63
 
64
- peers = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t)
65
- + sizeof(ngx_http_upstream_rr_peer_t) * (n - 1));
64
+ peers = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t));
66
65
  if (peers == NULL) {
67
66
  return NGX_ERROR;
68
67
  }
69
68
 
69
+ peer = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peer_t) * n);
70
+ if (peer == NULL) {
71
+ return NGX_ERROR;
72
+ }
73
+
70
74
  peers->single = (n == 1);
71
75
  peers->number = n;
72
76
  peers->weighted = (w != n);
@@ -74,7 +78,7 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
74
78
  peers->name = &us->host;
75
79
 
76
80
  n = 0;
77
- peer = peers->peer;
81
+ peerp = &peers->peer;
78
82
 
79
83
  for (i = 0; i < us->servers->nelts; i++) {
80
84
  if (server[i].backup) {
@@ -92,6 +96,9 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
92
96
  peer[n].fail_timeout = server[i].fail_timeout;
93
97
  peer[n].down = server[i].down;
94
98
  peer[n].server = server[i].name;
99
+
100
+ *peerp = &peer[n];
101
+ peerp = &peer[n].next;
95
102
  n++;
96
103
  }
97
104
  }
@@ -116,12 +123,16 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
116
123
  return NGX_OK;
117
124
  }
118
125
 
119
- backup = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t)
120
- + sizeof(ngx_http_upstream_rr_peer_t) * (n - 1));
126
+ backup = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t));
121
127
  if (backup == NULL) {
122
128
  return NGX_ERROR;
123
129
  }
124
130
 
131
+ peer = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peer_t) * n);
132
+ if (peer == NULL) {
133
+ return NGX_ERROR;
134
+ }
135
+
125
136
  peers->single = 0;
126
137
  backup->single = 0;
127
138
  backup->number = n;
@@ -130,7 +141,7 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
130
141
  backup->name = &us->host;
131
142
 
132
143
  n = 0;
133
- peer = backup->peer;
144
+ peerp = &backup->peer;
134
145
 
135
146
  for (i = 0; i < us->servers->nelts; i++) {
136
147
  if (!server[i].backup) {
@@ -148,6 +159,9 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
148
159
  peer[n].fail_timeout = server[i].fail_timeout;
149
160
  peer[n].down = server[i].down;
150
161
  peer[n].server = server[i].name;
162
+
163
+ *peerp = &peer[n];
164
+ peerp = &peer[n].next;
151
165
  n++;
152
166
  }
153
167
  }
@@ -184,19 +198,23 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
184
198
 
185
199
  n = u.naddrs;
186
200
 
187
- peers = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t)
188
- + sizeof(ngx_http_upstream_rr_peer_t) * (n - 1));
201
+ peers = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t));
189
202
  if (peers == NULL) {
190
203
  return NGX_ERROR;
191
204
  }
192
205
 
206
+ peer = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peer_t) * n);
207
+ if (peer == NULL) {
208
+ return NGX_ERROR;
209
+ }
210
+
193
211
  peers->single = (n == 1);
194
212
  peers->number = n;
195
213
  peers->weighted = 0;
196
214
  peers->total_weight = n;
197
215
  peers->name = &us->host;
198
216
 
199
- peer = peers->peer;
217
+ peerp = &peers->peer;
200
218
 
201
219
  for (i = 0; i < u.naddrs; i++) {
202
220
  peer[i].sockaddr = u.addrs[i].sockaddr;
@@ -207,6 +225,8 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
207
225
  peer[i].current_weight = 0;
208
226
  peer[i].max_fails = 1;
209
227
  peer[i].fail_timeout = 10;
228
+ *peerp = &peer[i];
229
+ peerp = &peer[i].next;
210
230
  }
211
231
 
212
232
  us->peer.data = peers;
@@ -236,7 +256,7 @@ ngx_http_upstream_init_round_robin_peer(ngx_http_request_t *r,
236
256
  }
237
257
 
238
258
  rrp->peers = us->peer.data;
239
- rrp->current = 0;
259
+ rrp->current = NULL;
240
260
 
241
261
  n = rrp->peers->number;
242
262
 
@@ -280,7 +300,7 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
280
300
  socklen_t socklen;
281
301
  ngx_uint_t i, n;
282
302
  struct sockaddr *sockaddr;
283
- ngx_http_upstream_rr_peer_t *peer;
303
+ ngx_http_upstream_rr_peer_t *peer, **peerp;
284
304
  ngx_http_upstream_rr_peers_t *peers;
285
305
  ngx_http_upstream_rr_peer_data_t *rrp;
286
306
 
@@ -295,18 +315,21 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
295
315
  r->upstream->peer.data = rrp;
296
316
  }
297
317
 
298
- peers = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_rr_peers_t)
299
- + sizeof(ngx_http_upstream_rr_peer_t) * (ur->naddrs - 1));
318
+ peers = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_rr_peers_t));
300
319
  if (peers == NULL) {
301
320
  return NGX_ERROR;
302
321
  }
303
322
 
323
+ peer = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_rr_peer_t)
324
+ * ur->naddrs);
325
+ if (peer == NULL) {
326
+ return NGX_ERROR;
327
+ }
328
+
304
329
  peers->single = (ur->naddrs == 1);
305
330
  peers->number = ur->naddrs;
306
331
  peers->name = &ur->host;
307
332
 
308
- peer = peers->peer;
309
-
310
333
  if (ur->sockaddr) {
311
334
  peer[0].sockaddr = ur->sockaddr;
312
335
  peer[0].socklen = ur->socklen;
@@ -316,8 +339,10 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
316
339
  peer[0].current_weight = 0;
317
340
  peer[0].max_fails = 1;
318
341
  peer[0].fail_timeout = 10;
342
+ peers->peer = peer;
319
343
 
320
344
  } else {
345
+ peerp = &peers->peer;
321
346
 
322
347
  for (i = 0; i < ur->naddrs; i++) {
323
348
 
@@ -356,11 +381,13 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
356
381
  peer[i].current_weight = 0;
357
382
  peer[i].max_fails = 1;
358
383
  peer[i].fail_timeout = 10;
384
+ *peerp = &peer[i];
385
+ peerp = &peer[i].next;
359
386
  }
360
387
  }
361
388
 
362
389
  rrp->peers = peers;
363
- rrp->current = 0;
390
+ rrp->current = NULL;
364
391
 
365
392
  if (rrp->peers->number <= 8 * sizeof(uintptr_t)) {
366
393
  rrp->tried = &rrp->data;
@@ -405,16 +432,17 @@ ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, void *data)
405
432
  pc->connection = NULL;
406
433
 
407
434
  peers = rrp->peers;
408
-
409
- /* ngx_lock_mutex(peers->mutex); */
435
+ ngx_http_upstream_rr_peers_wlock(peers);
410
436
 
411
437
  if (peers->single) {
412
- peer = &peers->peer[0];
438
+ peer = peers->peer;
413
439
 
414
440
  if (peer->down) {
415
441
  goto failed;
416
442
  }
417
443
 
444
+ rrp->current = peer;
445
+
418
446
  } else {
419
447
 
420
448
  /* there are several peers */
@@ -426,15 +454,17 @@ ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, void *data)
426
454
  }
427
455
 
428
456
  ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0,
429
- "get rr peer, current: %ui %i",
430
- rrp->current, peer->current_weight);
457
+ "get rr peer, current: %p %i",
458
+ peer, peer->current_weight);
431
459
  }
432
460
 
433
461
  pc->sockaddr = peer->sockaddr;
434
462
  pc->socklen = peer->socklen;
435
463
  pc->name = &peer->name;
436
464
 
437
- /* ngx_unlock_mutex(peers->mutex); */
465
+ peer->conns++;
466
+
467
+ ngx_http_upstream_rr_peers_unlock(peers);
438
468
 
439
469
  return NGX_OK;
440
470
 
@@ -442,8 +472,6 @@ failed:
442
472
 
443
473
  if (peers->next) {
444
474
 
445
- /* ngx_unlock_mutex(peers->mutex); */
446
-
447
475
  ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0, "backup servers");
448
476
 
449
477
  rrp->peers = peers->next;
@@ -452,25 +480,27 @@ failed:
452
480
  / (8 * sizeof(uintptr_t));
453
481
 
454
482
  for (i = 0; i < n; i++) {
455
- rrp->tried[i] = 0;
483
+ rrp->tried[i] = 0;
456
484
  }
457
485
 
486
+ ngx_http_upstream_rr_peers_unlock(peers);
487
+
458
488
  rc = ngx_http_upstream_get_round_robin_peer(pc, rrp);
459
489
 
460
490
  if (rc != NGX_BUSY) {
461
491
  return rc;
462
492
  }
463
493
 
464
- /* ngx_lock_mutex(peers->mutex); */
494
+ ngx_http_upstream_rr_peers_wlock(peers);
465
495
  }
466
496
 
467
497
  /* all peers failed, mark them as live for quick recovery */
468
498
 
469
- for (i = 0; i < peers->number; i++) {
470
- peers->peer[i].fails = 0;
499
+ for (peer = peers->peer; peer; peer = peer->next) {
500
+ peer->fails = 0;
471
501
  }
472
502
 
473
- /* ngx_unlock_mutex(peers->mutex); */
503
+ ngx_http_upstream_rr_peers_unlock(peers);
474
504
 
475
505
  pc->name = peers->name;
476
506
 
@@ -484,7 +514,7 @@ ngx_http_upstream_get_peer(ngx_http_upstream_rr_peer_data_t *rrp)
484
514
  time_t now;
485
515
  uintptr_t m;
486
516
  ngx_int_t total;
487
- ngx_uint_t i, n;
517
+ ngx_uint_t i, n, p;
488
518
  ngx_http_upstream_rr_peer_t *peer, *best;
489
519
 
490
520
  now = ngx_time();
@@ -492,7 +522,14 @@ ngx_http_upstream_get_peer(ngx_http_upstream_rr_peer_data_t *rrp)
492
522
  best = NULL;
493
523
  total = 0;
494
524
 
495
- for (i = 0; i < rrp->peers->number; i++) {
525
+ #if (NGX_SUPPRESS_WARN)
526
+ p = 0;
527
+ #endif
528
+
529
+ for (peer = rrp->peers->peer, i = 0;
530
+ peer;
531
+ peer = peer->next, i++)
532
+ {
496
533
 
497
534
  n = i / (8 * sizeof(uintptr_t));
498
535
  m = (uintptr_t) 1 << i % (8 * sizeof(uintptr_t));
@@ -501,8 +538,6 @@ ngx_http_upstream_get_peer(ngx_http_upstream_rr_peer_data_t *rrp)
501
538
  continue;
502
539
  }
503
540
 
504
- peer = &rrp->peers->peer[i];
505
-
506
541
  if (peer->down) {
507
542
  continue;
508
543
  }
@@ -523,6 +558,7 @@ ngx_http_upstream_get_peer(ngx_http_upstream_rr_peer_data_t *rrp)
523
558
 
524
559
  if (best == NULL || peer->current_weight > best->current_weight) {
525
560
  best = peer;
561
+ p = i;
526
562
  }
527
563
  }
528
564
 
@@ -530,12 +566,10 @@ ngx_http_upstream_get_peer(ngx_http_upstream_rr_peer_data_t *rrp)
530
566
  return NULL;
531
567
  }
532
568
 
533
- i = best - &rrp->peers->peer[0];
569
+ rrp->current = best;
534
570
 
535
- rrp->current = i;
536
-
537
- n = i / (8 * sizeof(uintptr_t));
538
- m = (uintptr_t) 1 << i % (8 * sizeof(uintptr_t));
571
+ n = p / (8 * sizeof(uintptr_t));
572
+ m = (uintptr_t) 1 << p % (8 * sizeof(uintptr_t));
539
573
 
540
574
  rrp->tried[n] |= m;
541
575
 
@@ -563,36 +597,46 @@ ngx_http_upstream_free_round_robin_peer(ngx_peer_connection_t *pc, void *data,
563
597
 
564
598
  /* TODO: NGX_PEER_KEEPALIVE */
565
599
 
600
+ peer = rrp->current;
601
+
602
+ ngx_http_upstream_rr_peers_rlock(rrp->peers);
603
+ ngx_http_upstream_rr_peer_lock(rrp->peers, peer);
604
+
566
605
  if (rrp->peers->single) {
606
+
607
+ peer->conns--;
608
+
609
+ ngx_http_upstream_rr_peer_unlock(rrp->peers, peer);
610
+ ngx_http_upstream_rr_peers_unlock(rrp->peers);
611
+
567
612
  pc->tries = 0;
568
613
  return;
569
614
  }
570
615
 
571
- peer = &rrp->peers->peer[rrp->current];
572
-
573
616
  if (state & NGX_PEER_FAILED) {
574
617
  now = ngx_time();
575
618
 
576
- /* ngx_lock_mutex(rrp->peers->mutex); */
577
-
578
619
  peer->fails++;
579
620
  peer->accessed = now;
580
621
  peer->checked = now;
581
622
 
582
623
  if (peer->max_fails) {
583
624
  peer->effective_weight -= peer->weight / peer->max_fails;
625
+
626
+ if (peer->fails >= peer->max_fails) {
627
+ ngx_log_error(NGX_LOG_WARN, pc->log, 0,
628
+ "upstream server temporarily disabled");
629
+ }
584
630
  }
585
631
 
586
632
  ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0,
587
- "free rr peer failed: %ui %i",
588
- rrp->current, peer->effective_weight);
633
+ "free rr peer failed: %p %i",
634
+ peer, peer->effective_weight);
589
635
 
590
636
  if (peer->effective_weight < 0) {
591
637
  peer->effective_weight = 0;
592
638
  }
593
639
 
594
- /* ngx_unlock_mutex(rrp->peers->mutex); */
595
-
596
640
  } else {
597
641
 
598
642
  /* mark peer live if check passed */
@@ -602,11 +646,14 @@ ngx_http_upstream_free_round_robin_peer(ngx_peer_connection_t *pc, void *data,
602
646
  }
603
647
  }
604
648
 
649
+ peer->conns--;
650
+
651
+ ngx_http_upstream_rr_peer_unlock(rrp->peers, peer);
652
+ ngx_http_upstream_rr_peers_unlock(rrp->peers);
653
+
605
654
  if (pc->tries) {
606
655
  pc->tries--;
607
656
  }
608
-
609
- /* ngx_unlock_mutex(rrp->peers->mutex); */
610
657
  }
611
658
 
612
659
 
@@ -618,14 +665,54 @@ ngx_http_upstream_set_round_robin_peer_session(ngx_peer_connection_t *pc,
618
665
  {
619
666
  ngx_http_upstream_rr_peer_data_t *rrp = data;
620
667
 
621
- ngx_int_t rc;
622
- ngx_ssl_session_t *ssl_session;
623
- ngx_http_upstream_rr_peer_t *peer;
668
+ ngx_int_t rc;
669
+ ngx_ssl_session_t *ssl_session;
670
+ ngx_http_upstream_rr_peer_t *peer;
671
+ #if (NGX_HTTP_UPSTREAM_ZONE)
672
+ int len;
673
+ #if OPENSSL_VERSION_NUMBER >= 0x0090707fL
674
+ const
675
+ #endif
676
+ u_char *p;
677
+ ngx_http_upstream_rr_peers_t *peers;
678
+ u_char buf[NGX_SSL_MAX_SESSION_SIZE];
679
+ #endif
680
+
681
+ peer = rrp->current;
682
+
683
+ #if (NGX_HTTP_UPSTREAM_ZONE)
684
+ peers = rrp->peers;
624
685
 
625
- peer = &rrp->peers->peer[rrp->current];
686
+ if (peers->shpool) {
687
+ ngx_http_upstream_rr_peers_rlock(peers);
688
+ ngx_http_upstream_rr_peer_lock(peers, peer);
626
689
 
627
- /* TODO: threads only mutex */
628
- /* ngx_lock_mutex(rrp->peers->mutex); */
690
+ if (peer->ssl_session == NULL) {
691
+ ngx_http_upstream_rr_peer_unlock(peers, peer);
692
+ ngx_http_upstream_rr_peers_unlock(peers);
693
+ return NGX_OK;
694
+ }
695
+
696
+ len = peer->ssl_session_len;
697
+
698
+ ngx_memcpy(buf, peer->ssl_session, len);
699
+
700
+ ngx_http_upstream_rr_peer_unlock(peers, peer);
701
+ ngx_http_upstream_rr_peers_unlock(peers);
702
+
703
+ p = buf;
704
+ ssl_session = d2i_SSL_SESSION(NULL, &p, len);
705
+
706
+ rc = ngx_ssl_set_session(pc->connection, ssl_session);
707
+
708
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
709
+ "set session: %p", ssl_session);
710
+
711
+ ngx_ssl_free_session(ssl_session);
712
+
713
+ return rc;
714
+ }
715
+ #endif
629
716
 
630
717
  ssl_session = peer->ssl_session;
631
718
 
@@ -634,8 +721,6 @@ ngx_http_upstream_set_round_robin_peer_session(ngx_peer_connection_t *pc,
634
721
  ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
635
722
  "set session: %p", ssl_session);
636
723
 
637
- /* ngx_unlock_mutex(rrp->peers->mutex); */
638
-
639
724
  return rc;
640
725
  }
641
726
 
@@ -646,8 +731,75 @@ ngx_http_upstream_save_round_robin_peer_session(ngx_peer_connection_t *pc,
646
731
  {
647
732
  ngx_http_upstream_rr_peer_data_t *rrp = data;
648
733
 
649
- ngx_ssl_session_t *old_ssl_session, *ssl_session;
650
- ngx_http_upstream_rr_peer_t *peer;
734
+ ngx_ssl_session_t *old_ssl_session, *ssl_session;
735
+ ngx_http_upstream_rr_peer_t *peer;
736
+ #if (NGX_HTTP_UPSTREAM_ZONE)
737
+ int len;
738
+ u_char *p;
739
+ ngx_http_upstream_rr_peers_t *peers;
740
+ u_char buf[NGX_SSL_MAX_SESSION_SIZE];
741
+ #endif
742
+
743
+ #if (NGX_HTTP_UPSTREAM_ZONE)
744
+ peers = rrp->peers;
745
+
746
+ if (peers->shpool) {
747
+
748
+ ssl_session = SSL_get0_session(pc->connection->ssl->connection);
749
+
750
+ if (ssl_session == NULL) {
751
+ return;
752
+ }
753
+
754
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
755
+ "save session: %p", ssl_session);
756
+
757
+ len = i2d_SSL_SESSION(ssl_session, NULL);
758
+
759
+ /* do not cache too big session */
760
+
761
+ if (len > NGX_SSL_MAX_SESSION_SIZE) {
762
+ return;
763
+ }
764
+
765
+ p = buf;
766
+ (void) i2d_SSL_SESSION(ssl_session, &p);
767
+
768
+ peer = rrp->current;
769
+
770
+ ngx_http_upstream_rr_peers_rlock(peers);
771
+ ngx_http_upstream_rr_peer_lock(peers, peer);
772
+
773
+ if (len > peer->ssl_session_len) {
774
+ ngx_shmtx_lock(&peers->shpool->mutex);
775
+
776
+ if (peer->ssl_session) {
777
+ ngx_slab_free_locked(peers->shpool, peer->ssl_session);
778
+ }
779
+
780
+ peer->ssl_session = ngx_slab_alloc_locked(peers->shpool, len);
781
+
782
+ ngx_shmtx_unlock(&peers->shpool->mutex);
783
+
784
+ if (peer->ssl_session == NULL) {
785
+ peer->ssl_session_len = 0;
786
+
787
+ ngx_http_upstream_rr_peer_unlock(peers, peer);
788
+ ngx_http_upstream_rr_peers_unlock(peers);
789
+ return;
790
+ }
791
+
792
+ peer->ssl_session_len = len;
793
+ }
794
+
795
+ ngx_memcpy(peer->ssl_session, buf, len);
796
+
797
+ ngx_http_upstream_rr_peer_unlock(peers, peer);
798
+ ngx_http_upstream_rr_peers_unlock(peers);
799
+
800
+ return;
801
+ }
802
+ #endif
651
803
 
652
804
  ssl_session = ngx_ssl_get_session(pc->connection);
653
805
 
@@ -658,16 +810,11 @@ ngx_http_upstream_save_round_robin_peer_session(ngx_peer_connection_t *pc,
658
810
  ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
659
811
  "save session: %p", ssl_session);
660
812
 
661
- peer = &rrp->peers->peer[rrp->current];
662
-
663
- /* TODO: threads only mutex */
664
- /* ngx_lock_mutex(rrp->peers->mutex); */
813
+ peer = rrp->current;
665
814
 
666
815
  old_ssl_session = peer->ssl_session;
667
816
  peer->ssl_session = ssl_session;
668
817
 
669
- /* ngx_unlock_mutex(rrp->peers->mutex); */
670
-
671
818
  if (old_ssl_session) {
672
819
 
673
820
  ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,