Mercurial > hg > nginx
comparison src/http/ngx_http_request.c @ 5541:fdb67cfc957d
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 | ef3d094bb6d3 |
children | 01e2a5bcdd8f |
comparison
equal
deleted
inserted
replaced
5540:3a8e19528b30 | 5541:fdb67cfc957d |
---|---|
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 |
633 | 619 |
634 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http recv(): %d", n); | 620 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http recv(): %d", n); |
635 | 621 |
636 if (n == -1) { | 622 if (n == -1) { |
637 if (err == NGX_EAGAIN) { | 623 if (err == NGX_EAGAIN) { |
638 | |
639 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT) | |
640 if (c->listening->deferred_accept) { | |
641 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, | |
642 "client timed out in deferred accept"); | |
643 ngx_http_close_connection(c); | |
644 return; | |
645 } | |
646 #endif | |
647 | 624 |
648 if (!rev->timer_set) { | 625 if (!rev->timer_set) { |
649 ngx_add_timer(rev, c->listening->post_accept_timeout); | 626 ngx_add_timer(rev, c->listening->post_accept_timeout); |
650 ngx_reusable_connection(c, 1); | 627 ngx_reusable_connection(c, 1); |
651 } | 628 } |