changeset 24:2ee28064a04a 0.4

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.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 15 Dec 2010 21:12:36 +0300
parents cad8bc39d98d
children c6396fef9295
files CHANGES ngx_http_upstream_keepalive_module.c t/memcached-keepalive.t t/stale.t
diffstat 4 files changed, 21 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES	Tue Sep 14 20:10:25 2010 +0400
+++ b/CHANGES	Wed Dec 15 21:12:36 2010 +0300
@@ -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):
 
--- a/ngx_http_upstream_keepalive_module.c	Tue Sep 14 20:10:25 2010 +0400
+++ b/ngx_http_upstream_keepalive_module.c	Wed Dec 15 21:12:36 2010 +0300
@@ -395,6 +395,10 @@
 
     c = ev->data;
 
+    if (c->close) {
+        goto close;
+    }
+
     n = recv(c->fd, buf, 1, MSG_PEEK);
 
     if (n == -1 && ngx_socket_errno == NGX_EAGAIN) {
--- a/t/memcached-keepalive.t	Tue Sep 14 20:10:25 2010 +0400
+++ b/t/memcached-keepalive.t	Wed Dec 15 21:12:36 2010 +0300
@@ -20,12 +20,11 @@
 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 @@
 	$memd2->stats()->{total}->{total_connections}, $total + 2,
 	'connection per backend');
 
+$t->stop();
+
+like(`grep -F '[alert]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no alerts');
+
 ###############################################################################
--- a/t/stale.t	Tue Sep 14 20:10:25 2010 +0400
+++ b/t/stale.t	Wed Dec 15 21:12:36 2010 +0300
@@ -20,7 +20,7 @@
 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 @@
 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');
+
 ###############################################################################