Welcome! Log In Create A New Profile

Advanced

[nginx] Fixed TCP_DEFER_ACCEPT handling (ticket #353).

Maxim Dounin
January 28, 2014 07:04AM
details: http://hg.nginx.org/nginx/rev/fdb67cfc957d
branches:
changeset: 5541:fdb67cfc957d
user: Maxim Dounin <mdounin@mdounin.ru>
date: Tue Jan 28 15:40:46 2014 +0400
description:
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.

diffstat:

src/core/ngx_connection.c | 8 +++++++-
src/http/ngx_http_request.c | 23 -----------------------
2 files changed, 7 insertions(+), 24 deletions(-)

diffs (58 lines):

diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c
--- a/src/core/ngx_connection.c
+++ b/src/core/ngx_connection.c
@@ -701,7 +701,13 @@ ngx_configure_listening_sockets(ngx_cycl
if (ls[i].add_deferred || ls[i].delete_deferred) {

if (ls[i].add_deferred) {
- value = (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.
+ */
+ value = 1;

} else {
value = 0;
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
--- 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_

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);
@@ -636,15 +622,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);

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Fixed TCP_DEFER_ACCEPT handling (ticket #353).

Maxim Dounin 890 January 28, 2014 07:04AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 192
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready