diff options
author | Maxim Dounin <mdounin@mdounin.ru> | 2014-01-28 15:40:46 +0400 |
---|---|---|
committer | Maxim Dounin <mdounin@mdounin.ru> | 2014-01-28 15:40:46 +0400 |
commit | 4cdd17f6bff9b27b3b51a8b5f9d4798985485271 (patch) | |
tree | bccbeb1d7c7ed1659567700595684cc43ef9d64f | |
parent | 612f981744dd4eaa9c25542d5485844e5109ce7f (diff) | |
download | nginx-4cdd17f6bff9b27b3b51a8b5f9d4798985485271.tar.gz nginx-4cdd17f6bff9b27b3b51a8b5f9d4798985485271.zip |
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.
-rw-r--r-- | src/core/ngx_connection.c | 8 | ||||
-rw-r--r-- | src/http/ngx_http_request.c | 23 |
2 files changed, 7 insertions, 24 deletions
diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c index 7ed781e0a..986bf0d02 100644 --- a/src/core/ngx_connection.c +++ b/src/core/ngx_connection.c @@ -647,7 +647,13 @@ ngx_configure_listening_sockets(ngx_cycle_t *cycle) if (ls[i].add_deferred || ls[i].delete_deferred) { if (ls[i].add_deferred) { - timeout = (int) (ls[i].post_accept_timeout / 1000); + /* + * There is no way to find out how long a connection was + * in queue (and a connection may bypass deferred queue at all + * if syncookies were used), hence we use 1 second timeout + * here. + */ + timeout = 1; } else { timeout = 0; diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index c8c5d153f..1be2d463f 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -423,20 +423,6 @@ ngx_http_wait_request_handler(ngx_event_t *rev) if (n == NGX_AGAIN) { -#if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT) - if (c->listening->deferred_accept -#if (NGX_HTTP_SSL) - && c->ssl == NULL -#endif - ) - { - ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, - "client timed out in deferred accept"); - ngx_http_close_connection(c); - return; - } -#endif - if (!rev->timer_set) { ngx_add_timer(rev, c->listening->post_accept_timeout); ngx_reusable_connection(c, 1); @@ -635,15 +621,6 @@ ngx_http_ssl_handshake(ngx_event_t *rev) if (n == -1) { if (err == NGX_EAGAIN) { -#if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT) - if (c->listening->deferred_accept) { - ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, - "client timed out in deferred accept"); - ngx_http_close_connection(c); - return; - } -#endif - if (!rev->timer_set) { ngx_add_timer(rev, c->listening->post_accept_timeout); ngx_reusable_connection(c, 1); |