comparison src/event/ngx_event_accept.c @ 674:4dcaf40cc702 NGINX_1_3_0

nginx 1.3.0 *) Feature: the "debug_connection" directive now supports IPv6 addresses and the "unix:" parameter. *) Feature: the "set_real_ip_from" directive and the "proxy" parameter of the "geo" directive now support IPv6 addresses. *) Feature: the "real_ip_recursive", "geoip_proxy", and "geoip_proxy_recursive" directives. *) Feature: the "proxy_recursive" parameter of the "geo" directive. *) Bugfix: a segmentation fault might occur in a worker process if the "resolver" directive was used. *) Bugfix: a segmentation fault might occur in a worker process if the "fastcgi_pass", "scgi_pass", or "uwsgi_pass" directives were used and backend returned incorrect response. *) Bugfix: a segmentation fault might occur in a worker process if the "rewrite" directive was used and new request arguments in a replacement used variables. *) Bugfix: nginx might hog CPU if the open file resource limit was reached. *) Bugfix: nginx might loop infinitely over backends if the "proxy_next_upstream" directive with the "http_404" parameter was used and there were backup servers specified in an upstream block. *) Bugfix: adding the "down" parameter of the "server" directive might cause unneeded client redistribution among backend servers if the "ip_hash" directive was used. *) Bugfix: socket leak. Thanks to Yichun Zhang. *) Bugfix: in the ngx_http_fastcgi_module.
author Igor Sysoev <http://sysoev.ru>
date Tue, 15 May 2012 00:00:00 +0400
parents d0f7a625f27c
children
comparison
equal deleted inserted replaced
673:1e5c7a976f48 674:4dcaf40cc702
19 ngx_event_accept(ngx_event_t *ev) 19 ngx_event_accept(ngx_event_t *ev)
20 { 20 {
21 socklen_t socklen; 21 socklen_t socklen;
22 ngx_err_t err; 22 ngx_err_t err;
23 ngx_log_t *log; 23 ngx_log_t *log;
24 ngx_uint_t level;
24 ngx_socket_t s; 25 ngx_socket_t s;
25 ngx_event_t *rev, *wev; 26 ngx_event_t *rev, *wev;
26 ngx_listening_t *ls; 27 ngx_listening_t *ls;
27 ngx_connection_t *c, *lc; 28 ngx_connection_t *c, *lc;
28 ngx_event_conf_t *ecf; 29 ngx_event_conf_t *ecf;
29 u_char sa[NGX_SOCKADDRLEN]; 30 u_char sa[NGX_SOCKADDRLEN];
30 #if (NGX_HAVE_ACCEPT4) 31 #if (NGX_HAVE_ACCEPT4)
31 static ngx_uint_t use_accept4 = 1; 32 static ngx_uint_t use_accept4 = 1;
32 #endif 33 #endif
33 34
35 if (ev->timedout) {
36 if (ngx_enable_accept_events((ngx_cycle_t *) ngx_cycle) != NGX_OK) {
37 return;
38 }
39
40 ev->timedout = 0;
41 }
42
34 ecf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_event_core_module); 43 ecf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_event_core_module);
35 44
36 if (ngx_event_flags & NGX_USE_RTSIG_EVENT) { 45 if (ngx_event_flags & NGX_USE_RTSIG_EVENT) {
37 ev->available = 1; 46 ev->available = 1;
38 47
68 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, err, 77 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, err,
69 "accept() not ready"); 78 "accept() not ready");
70 return; 79 return;
71 } 80 }
72 81
82 level = NGX_LOG_ALERT;
83
84 if (err == NGX_ECONNABORTED) {
85 level = NGX_LOG_ERR;
86
87 } else if (err == NGX_EMFILE || err == NGX_ENFILE) {
88 level = NGX_LOG_CRIT;
89 }
90
73 #if (NGX_HAVE_ACCEPT4) 91 #if (NGX_HAVE_ACCEPT4)
74 ngx_log_error((ngx_uint_t) ((err == NGX_ECONNABORTED) ? 92 ngx_log_error(level, ev->log, err,
75 NGX_LOG_ERR : NGX_LOG_ALERT),
76 ev->log, err,
77 use_accept4 ? "accept4() failed" : "accept() failed"); 93 use_accept4 ? "accept4() failed" : "accept() failed");
78 94
79 if (use_accept4 && err == NGX_ENOSYS) { 95 if (use_accept4 && err == NGX_ENOSYS) {
80 use_accept4 = 0; 96 use_accept4 = 0;
81 ngx_inherited_nonblocking = 0; 97 ngx_inherited_nonblocking = 0;
82 continue; 98 continue;
83 } 99 }
84 #else 100 #else
85 ngx_log_error((ngx_uint_t) ((err == NGX_ECONNABORTED) ? 101 ngx_log_error(level, ev->log, err, "accept() failed");
86 NGX_LOG_ERR : NGX_LOG_ALERT),
87 ev->log, err, "accept() failed");
88 #endif 102 #endif
89 103
90 if (err == NGX_ECONNABORTED) { 104 if (err == NGX_ECONNABORTED) {
91 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { 105 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
92 ev->available--; 106 ev->available--;
93 } 107 }
94 108
95 if (ev->available) { 109 if (ev->available) {
96 continue; 110 continue;
111 }
112 }
113
114 if (err == NGX_EMFILE || err == NGX_ENFILE) {
115 if (ngx_disable_accept_events((ngx_cycle_t *) ngx_cycle)
116 != NGX_OK)
117 {
118 return;
119 }
120
121 if (ngx_use_accept_mutex) {
122 if (ngx_accept_mutex_held) {
123 ngx_shmtx_unlock(&ngx_accept_mutex);
124 ngx_accept_mutex_held = 0;
125 }
126
127 ngx_accept_disabled = 1;
128
129 } else {
130 ngx_add_timer(ev, ecf->accept_mutex_delay);
97 } 131 }
98 } 132 }
99 133
100 return; 134 return;
101 } 135 }
250 } 284 }
251 285
252 #if (NGX_DEBUG) 286 #if (NGX_DEBUG)
253 { 287 {
254 288
255 in_addr_t i; 289 struct sockaddr_in *sin;
256 ngx_event_debug_t *dc; 290 ngx_cidr_t *cidr;
257 struct sockaddr_in *sin; 291 ngx_uint_t i;
258 292 #if (NGX_HAVE_INET6)
259 sin = (struct sockaddr_in *) sa; 293 struct sockaddr_in6 *sin6;
260 dc = ecf->debug_connection.elts; 294 ngx_uint_t n;
295 #endif
296
297 cidr = ecf->debug_connection.elts;
261 for (i = 0; i < ecf->debug_connection.nelts; i++) { 298 for (i = 0; i < ecf->debug_connection.nelts; i++) {
262 if ((sin->sin_addr.s_addr & dc[i].mask) == dc[i].addr) { 299 if (cidr[i].family != c->sockaddr->sa_family) {
263 log->log_level = NGX_LOG_DEBUG_CONNECTION|NGX_LOG_DEBUG_ALL; 300 goto next;
301 }
302
303 switch (cidr[i].family) {
304
305 #if (NGX_HAVE_INET6)
306 case AF_INET6:
307 sin6 = (struct sockaddr_in6 *) c->sockaddr;
308 for (n = 0; n < 16; n++) {
309 if ((sin6->sin6_addr.s6_addr[n]
310 & cidr[i].u.in6.mask.s6_addr[n])
311 != cidr[i].u.in6.addr.s6_addr[n])
312 {
313 goto next;
314 }
315 }
264 break; 316 break;
265 } 317 #endif
318
319 #if (NGX_HAVE_UNIX_DOMAIN)
320 case AF_UNIX:
321 break;
322 #endif
323
324 default: /* AF_INET */
325 sin = (struct sockaddr_in *) c->sockaddr;
326 if ((sin->sin_addr.s_addr & cidr[i].u.in.mask)
327 != cidr[i].u.in.addr)
328 {
329 goto next;
330 }
331 break;
332 }
333
334 log->log_level = NGX_LOG_DEBUG_CONNECTION|NGX_LOG_DEBUG_ALL;
335 break;
336
337 next:
338 continue;
266 } 339 }
267 340
268 } 341 }
269 #endif 342 #endif
270 343
342 ls = cycle->listening.elts; 415 ls = cycle->listening.elts;
343 for (i = 0; i < cycle->listening.nelts; i++) { 416 for (i = 0; i < cycle->listening.nelts; i++) {
344 417
345 c = ls[i].connection; 418 c = ls[i].connection;
346 419
420 if (c->read->active) {
421 continue;
422 }
423
347 if (ngx_event_flags & NGX_USE_RTSIG_EVENT) { 424 if (ngx_event_flags & NGX_USE_RTSIG_EVENT) {
348 425
349 if (ngx_add_conn(c) == NGX_ERROR) { 426 if (ngx_add_conn(c) == NGX_ERROR) {
350 return NGX_ERROR; 427 return NGX_ERROR;
351 } 428 }