Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

bugfix: the "open socket #n left in connection" alerts would appear i…

…n the nginx error log file when the pg connection pool was used and the worker process was shutting down. this issue could be captured by running t/sanity.t with the environment TEST_NGINX_USE_HUP=1.
  • Loading branch information...
commit c8aa3d390f80257bd6e9c63e5fb43be79820ad8c 1 parent 714081d
@agentzh agentzh authored
View
11 src/ngx_postgres_keepalive.c
@@ -269,6 +269,10 @@ ngx_postgres_keepalive_close_handler(ngx_event_t *ev)
c = ev->data;
item = c->data;
+ if (c->close) {
+ goto close;
+ }
+
if (PQconsumeInput(item->pgconn) && !PQisBusy(item->pgconn)) {
res = PQgetResult(item->pgconn);
if (res == NULL) {
@@ -283,13 +287,12 @@ ngx_postgres_keepalive_close_handler(ngx_event_t *ev)
"postgres: received result on idle keepalive connection");
}
+close:
pgscf = item->srv_conf;
- ngx_queue_remove(&item->queue);
-
- ngx_postgres_upstream_free_connection(ev->log, item->connection,
- item->pgconn, pgscf);
+ ngx_postgres_upstream_free_connection(ev->log, c, item->pgconn, pgscf);
+ ngx_queue_remove(&item->queue);
ngx_queue_insert_head(&pgscf->free, &item->queue);
dd("returning");
View
2  src/ngx_postgres_upstream.c
@@ -572,6 +572,8 @@ ngx_postgres_upstream_free_connection(ngx_log_t *log, ngx_connection_t *c,
#endif
ngx_free_connection(c);
+
+ c->fd = (ngx_socket_t) -1;
}
/* free spot in keepalive connection pool */
View
24 t/sanity.t
@@ -5,7 +5,7 @@ use Test::Nginx::Socket;
repeat_each(2);
-plan tests => repeat_each() * (blocks() * 3);
+plan tests => repeat_each() * (blocks() * 5);
$ENV{TEST_NGINX_POSTGRESQL_HOST} ||= '127.0.0.1';
$ENV{TEST_NGINX_POSTGRESQL_PORT} ||= 5432;
@@ -69,6 +69,9 @@ Content-Type: application/x-resty-dbd-stream
"bob". # field data
"\x{00}" # row list terminator
--- timeout: 10
+--- no_error_log
+[alert]
+[error]
@@ -115,6 +118,9 @@ Content-Type: application/x-resty-dbd-stream
"bob". # field data
"\x{00}" # row list terminator
--- timeout: 10
+--- no_error_log
+[alert]
+[error]
@@ -142,6 +148,10 @@ Content-Type: application/x-resty-dbd-stream
"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
"\x{00}\x{00}" # col count
--- timeout: 10
+--- no_error_log
+[alert]
+[error]
+--- LAST
@@ -178,6 +188,9 @@ Content-Type: application/x-resty-dbd-stream
"name". # col name data
"\x{00}" # row list terminator
--- timeout: 10
+--- no_error_log
+[alert]
+[error]
@@ -206,6 +219,9 @@ Content-Type: application/x-resty-dbd-stream
"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
"\x{00}\x{00}" # col count
--- timeout: 10
+--- no_error_log
+[alert]
+[error]
@@ -224,6 +240,9 @@ Content-Type: application/x-resty-dbd-stream
--- response_body eval
""
--- timeout: 10
+--- no_error_log
+[alert]
+[error]
@@ -275,3 +294,6 @@ Content-Type: application/x-resty-dbd-stream
"bob". # field data
"\x{00}" # row list terminator
--- timeout: 10
+--- no_error_log
+[alert]
+[error]
Please sign in to comment.
Something went wrong with that request. Please try again.