comparison src/http/ngx_http_request.c @ 5569:462ae7eedc68 stable-1.4

Fixed TCP_DEFER_ACCEPT handling (ticket #353). Backed out 05a56ebb084a, as it turns out that kernel can return connections without any delay if syncookies are used. This basically means we can't assume anything about connections returned with deferred accept set. To solve original problem the 05a56ebb084a tried to solve, i.e. to don't wait longer than needed if a connection was accepted after deferred accept timeout, this patch changes a timeout set with setsockopt(TCP_DEFER_ACCEPT) to 1 second, unconditionally. This is believed to be enough for speed improvements, and doesn't imply major changes to timeouts used. Note that before 2.6.32 connections were dropped after a timeout. Though it is believed that 1s is still appropriate for kernels before 2.6.32, as previously tcp_synack_retries controlled the actual timeout and 1s results in more than 1 minute actual timeout by default.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 28 Jan 2014 15:40:46 +0400
parents 95a30deca8ad
children
comparison
equal deleted inserted replaced
5568:560de9681661 5569:462ae7eedc68
421 421
422 n = c->recv(c, b->last, size); 422 n = c->recv(c, b->last, size);
423 423
424 if (n == NGX_AGAIN) { 424 if (n == NGX_AGAIN) {
425 425
426 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
427 if (c->listening->deferred_accept
428 #if (NGX_HTTP_SSL)
429 && c->ssl == NULL
430 #endif
431 )
432 {
433 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT,
434 "client timed out in deferred accept");
435 ngx_http_close_connection(c);
436 return;
437 }
438 #endif
439
440 if (!rev->timer_set) { 426 if (!rev->timer_set) {
441 ngx_add_timer(rev, c->listening->post_accept_timeout); 427 ngx_add_timer(rev, c->listening->post_accept_timeout);
442 ngx_reusable_connection(c, 1); 428 ngx_reusable_connection(c, 1);
443 } 429 }
444 430
632 618
633 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http recv(): %d", n); 619 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http recv(): %d", n);
634 620
635 if (n == -1) { 621 if (n == -1) {
636 if (err == NGX_EAGAIN) { 622 if (err == NGX_EAGAIN) {
637
638 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
639 if (c->listening->deferred_accept) {
640 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT,
641 "client timed out in deferred accept");
642 ngx_http_close_connection(c);
643 return;
644 }
645 #endif
646 623
647 if (!rev->timer_set) { 624 if (!rev->timer_set) {
648 ngx_add_timer(rev, c->listening->post_accept_timeout); 625 ngx_add_timer(rev, c->listening->post_accept_timeout);
649 ngx_reusable_connection(c, 1); 626 ngx_reusable_connection(c, 1);
650 } 627 }