# HG changeset patch # User Maxim Dounin # Date 1292436756 -10800 # Node ID 2ee28064a04ad5ab4eb73633ec29ee378bae85d1 # Parent cad8bc39d98d4d24a69f555387c503d9881d3af4 Keepalive: correctly close connections on gracefull shutdown. On gracefull shutdown nginx calls read handler on all idle connections with c->close set. Make sure we don't confuse such read handler calls with stale events and actually close connections. This fixes "open socket ... left in connection ..." alerts. diff --git a/CHANGES b/CHANGES --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,10 @@ + +Changes with upstream keepalive module 0.4 (2010-12-15): + + *) Bugfix: the "[alert] ... open socket ... left in connection ..." + messages were logged on nginx worker process gracefull exit for + each cached connection; the bug had appeared in 0.3. + Changes with upstream keepalive module 0.3 (2010-09-14): diff --git a/ngx_http_upstream_keepalive_module.c b/ngx_http_upstream_keepalive_module.c --- a/ngx_http_upstream_keepalive_module.c +++ b/ngx_http_upstream_keepalive_module.c @@ -395,6 +395,10 @@ ngx_http_upstream_keepalive_close_handle c = ev->data; + if (c->close) { + goto close; + } + n = recv(c->fd, buf, 1, MSG_PEEK); if (n == -1 && ngx_socket_errno == NGX_EAGAIN) { diff --git a/t/memcached-keepalive.t b/t/memcached-keepalive.t --- a/t/memcached-keepalive.t +++ b/t/memcached-keepalive.t @@ -20,12 +20,11 @@ select STDOUT; $| = 1; eval { require Cache::Memcached; }; plan(skip_all => 'Cache::Memcached not installed') if $@; -my $t = Test::Nginx->new()->has('rewrite')->has_daemon('memcached')->plan(16) +my $t = Test::Nginx->new()->has('rewrite')->has_daemon('memcached')->plan(17) ->write_file_expand('nginx.conf', <<'EOF'); %%TEST_GLOBALS%% -master_process off; daemon off; events { @@ -202,4 +201,8 @@ is($memd1->stats()->{total}->{total_conn $memd2->stats()->{total}->{total_connections}, $total + 2, 'connection per backend'); +$t->stop(); + +like(`grep -F '[alert]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no alerts'); + ############################################################################### diff --git a/t/stale.t b/t/stale.t --- a/t/stale.t +++ b/t/stale.t @@ -20,7 +20,7 @@ select STDOUT; $| = 1; eval { require Cache::Memcached; }; plan(skip_all => 'Cache::Memcached not installed') if $@; -my $t = Test::Nginx->new()->has('rewrite')->has_daemon('memcached')->plan(1) +my $t = Test::Nginx->new()->has('rewrite')->has_daemon('memcached')->plan(2) ->write_file_expand('nginx.conf', <<'EOF'); %%TEST_GLOBALS%% @@ -107,4 +107,8 @@ for (1 .. 100) { cmp_ok($memd1->stats()->{total}->{total_connections}, '<=', $total + 2, 'only one connection per worker used'); +$t->stop(); + +like(`grep -F '[alert]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no alerts'); + ###############################################################################