diff --git a/src/ngx_postgres_ddebug.h b/src/ngx_postgres_ddebug.h index 7cc05ecd..38253fca 100644 --- a/src/ngx_postgres_ddebug.h +++ b/src/ngx_postgres_ddebug.h @@ -29,6 +29,7 @@ #ifndef _NGX_POSTGRES_DDEBUG_H_ #define _NGX_POSTGRES_DDEBUG_H_ +#include #include #if defined(DDEBUG) && (DDEBUG) diff --git a/src/ngx_postgres_escape.c b/src/ngx_postgres_escape.c index 3b589741..dd781947 100644 --- a/src/ngx_postgres_escape.c +++ b/src/ngx_postgres_escape.c @@ -90,6 +90,7 @@ ngx_postgres_escape_string(ngx_http_script_engine_t *e) dd("returning"); done: + v->valid = 1; v->no_cacheable = 0; v->not_found = 0; diff --git a/src/ngx_postgres_keepalive.c b/src/ngx_postgres_keepalive.c index 9f10749b..6575338c 100644 --- a/src/ngx_postgres_keepalive.c +++ b/src/ngx_postgres_keepalive.c @@ -85,6 +85,9 @@ ngx_postgres_keepalive_get_peer_single(ngx_peer_connection_t *pc, c->idle = 0; c->log = pc->log; +#if defined(nginx_version) && (nginx_version >= 1001004) + c->pool->log = pc->log; +#endif c->read->log = pc->log; c->write->log = pc->log; @@ -140,6 +143,9 @@ ngx_postgres_keepalive_get_peer_multi(ngx_peer_connection_t *pc, c->idle = 0; c->log = pc->log; +#if defined(nginx_version) && (nginx_version >= 1001004) + c->pool->log = pc->log; +#endif c->read->log = pc->log; c->write->log = pc->log; @@ -235,6 +241,9 @@ ngx_postgres_keepalive_free_peer(ngx_peer_connection_t *pc, c->data = item; c->idle = 1; c->log = ngx_cycle->log; +#if defined(nginx_version) && (nginx_version >= 1001004) + c->pool->log = ngx_cycle->log; +#endif c->read->log = ngx_cycle->log; c->write->log = ngx_cycle->log; @@ -288,6 +297,7 @@ ngx_postgres_keepalive_close_handler(ngx_event_t *ev) } close: + pgscf = item->srv_conf; ngx_postgres_upstream_free_connection(ev->log, c, item->pgconn, pgscf); diff --git a/src/ngx_postgres_module.c b/src/ngx_postgres_module.c index 176d828e..365de007 100644 --- a/src/ngx_postgres_module.c +++ b/src/ngx_postgres_module.c @@ -872,6 +872,7 @@ ngx_postgres_conf_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) pgrcf->handler = e[i].handler; found: + if (cf->args->nelts == 3) { /* default rewrite */ dd("default rewrite"); diff --git a/src/ngx_postgres_output.c b/src/ngx_postgres_output.c index 71e4d8dd..9fa5481c 100644 --- a/src/ngx_postgres_output.c +++ b/src/ngx_postgres_output.c @@ -260,6 +260,7 @@ ngx_postgres_output_rds(ngx_http_request_t *r, PGresult *res) } done: + last->next = NULL; /* set output response */ @@ -548,7 +549,7 @@ ngx_postgres_output_chain(ngx_http_request_t *r, ngx_chain_t *cl) pglcf = ngx_http_get_module_loc_conf(r, ngx_postgres_module); pgctx = ngx_http_get_module_ctx(r, ngx_postgres_module); - r->headers_out.status = pgctx->status ? abs(pgctx->status) + r->headers_out.status = pgctx->status ? ngx_abs(pgctx->status) : NGX_HTTP_OK; if (pglcf->output_handler == &ngx_postgres_output_rds) { diff --git a/src/ngx_postgres_processor.c b/src/ngx_postgres_processor.c index 1b4dce1d..d25c0541 100644 --- a/src/ngx_postgres_processor.c +++ b/src/ngx_postgres_processor.c @@ -103,6 +103,7 @@ ngx_postgres_process_events(ngx_http_request_t *r) return; failed: + ngx_postgres_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR); dd("returning"); @@ -200,6 +201,7 @@ ngx_postgres_upstream_connect(ngx_http_request_t *r, ngx_connection_t *pgxc, } done: + /* remove connection timeout from new connection */ if (pgxc->write->timer_set) { ngx_del_timer(pgxc->write); diff --git a/src/ngx_postgres_upstream.c b/src/ngx_postgres_upstream.c index ceb24ded..919029b0 100644 --- a/src/ngx_postgres_upstream.c +++ b/src/ngx_postgres_upstream.c @@ -103,6 +103,9 @@ ngx_postgres_upstream_init(ngx_conf_t *cf, ngx_http_upstream_srv_conf_t *uscf) } peers->peer[n].host.len = ngx_sock_ntop(peers->peer[n].sockaddr, +#if defined(nginx_version) && (nginx_version >= 1005003) + peers->peer[n].socklen, +#endif peers->peer[n].host.data, NGX_SOCKADDR_STRLEN, 0); if (peers->peer[n].host.len == 0) { @@ -219,6 +222,7 @@ ngx_postgres_upstream_init_peer(ngx_http_request_t *r, return NGX_OK; failed: + #if defined(nginx_version) && (nginx_version >= 8017) dd("returning NGX_ERROR"); return NGX_ERROR; @@ -457,10 +461,12 @@ ngx_postgres_upstream_get_peer(ngx_peer_connection_t *pc, void *data) return NGX_AGAIN; bad_add: + ngx_log_error(NGX_LOG_ERR, pc->log, 0, "postgres: failed to add nginx connection"); invalid: + ngx_postgres_upstream_free_connection(pc->log, pc->connection, pgdt->pgconn, pgscf); @@ -470,6 +476,7 @@ ngx_postgres_upstream_get_peer(ngx_peer_connection_t *pc, void *data) #else failed: + /* a bit hack-ish way to return error response (setup part) */ pc->connection = ngx_get_connection(0, pc->log); @@ -554,11 +561,19 @@ ngx_postgres_upstream_free_connection(ngx_log_t *log, ngx_connection_t *c, } } +#if defined(nginx_version) && nginx_version >= 1007005 + if (rev->posted) { +#else if (rev->prev) { +#endif ngx_delete_posted_event(rev); } +#if defined(nginx_version) && nginx_version >= 1007005 + if (wev->posted) { +#else if (wev->prev) { +#endif ngx_delete_posted_event(wev); } diff --git a/src/ngx_postgres_util.c b/src/ngx_postgres_util.c index 11b27979..ae7de38c 100644 --- a/src/ngx_postgres_util.c +++ b/src/ngx_postgres_util.c @@ -45,7 +45,9 @@ void ngx_postgres_upstream_finalize_request(ngx_http_request_t *r, ngx_http_upstream_t *u, ngx_int_t rc) { +#if defined(nginx_version) && (nginx_version < 1009001) ngx_time_t *tp; +#endif dd("entering"); @@ -61,10 +63,15 @@ ngx_postgres_upstream_finalize_request(ngx_http_request_t *r, u->resolved->ctx = NULL; } +#if defined(nginx_version) && (nginx_version >= 1009001) + if (u->state && u->state->response_time) { + u->state->response_time = ngx_current_msec - u->state->response_time; +#else if (u->state && u->state->response_sec) { tp = ngx_timeofday(); u->state->response_sec = tp->sec - u->state->response_sec; u->state->response_msec = tp->msec - u->state->response_msec; +#endif if (u->pipe) { u->state->response_length = u->pipe->read_length; diff --git a/t/000_init.t b/t/000_init.t index ef50138b..832244e4 100644 --- a/t/000_init.t +++ b/t/000_init.t @@ -5,7 +5,7 @@ use Test::Nginx::Socket; repeat_each(1); -plan tests => repeat_each() * blocks(); +plan tests => repeat_each() * 2 * blocks(); $ENV{TEST_NGINX_POSTGRESQL_HOST} ||= '127.0.0.1'; $ENV{TEST_NGINX_POSTGRESQL_PORT} ||= 5432; @@ -36,6 +36,8 @@ __DATA__ GET /init --- error_code: 200 --- timeout: 10 +--- no_error_log +[error] @@ -50,6 +52,8 @@ GET /init GET /init --- error_code: 200 --- timeout: 10 +--- no_error_log +[error] @@ -64,6 +68,8 @@ GET /init GET /init --- error_code: 200 --- timeout: 10 +--- no_error_log +[error] @@ -78,6 +84,8 @@ GET /init GET /init --- error_code: 200 --- timeout: 10 +--- no_error_log +[error] @@ -95,6 +103,8 @@ GET /init GET /init --- error_code: 200 --- timeout: 10 +--- no_error_log +[error] @@ -109,6 +119,8 @@ GET /init GET /init --- error_code: 200 --- timeout: 10 +--- no_error_log +[error] @@ -126,6 +138,8 @@ GET /init GET /init --- error_code: 200 --- timeout: 10 +--- no_error_log +[error] @@ -140,6 +154,8 @@ GET /init GET /init --- error_code: 200 --- timeout: 10 +--- no_error_log +[error] @@ -154,3 +170,5 @@ GET /init GET /init --- error_code: 200 --- timeout: 10 +--- no_error_log +[error] diff --git a/t/output.t b/t/output.t index a564bf86..b4ba503a 100644 --- a/t/output.t +++ b/t/output.t @@ -82,7 +82,7 @@ test -=== TEST 5: value - NULL value +=== TEST 4: value - NULL value --- http_config eval: $::http_config --- config default_type text/plain; @@ -99,7 +99,7 @@ GET /postgres -=== TEST 6: value - empty value +=== TEST 5: value - empty value --- http_config eval: $::http_config --- config default_type text/plain; @@ -116,7 +116,7 @@ GET /postgres -=== TEST 7: text - sanity +=== TEST 6: text - sanity --- http_config eval: $::http_config --- config default_type text/plain; @@ -143,7 +143,7 @@ Content-Type: text/plain -=== TEST 8: rds - sanity (configured) +=== TEST 7: rds - sanity (configured) --- http_config eval: $::http_config --- config location /postgres { @@ -179,7 +179,7 @@ Content-Type: application/x-resty-dbd-stream -=== TEST 9: rds - sanity (default) +=== TEST 8: rds - sanity (default) --- http_config eval: $::http_config --- config location /postgres { @@ -214,7 +214,7 @@ Content-Type: application/x-resty-dbd-stream -=== TEST 10: inheritance +=== TEST 9: inheritance --- http_config eval: $::http_config --- config default_type text/plain; @@ -235,7 +235,7 @@ test -=== TEST 11: inheritance (mixed, don't inherit) +=== TEST 10: inheritance (mixed, don't inherit) --- http_config eval: $::http_config --- config postgres_output text; @@ -256,7 +256,7 @@ GET /postgres -=== TEST 14: value - sanity (request with known extension) +=== TEST 11: value - sanity (request with known extension) --- http_config eval: $::http_config --- config default_type text/plain; @@ -277,7 +277,7 @@ test -=== TEST 15: value - bytea returned in text format +=== TEST 12: value - bytea returned in text format --- http_config eval: $::http_config --- config default_type text/plain; @@ -298,7 +298,7 @@ Content-Type: text/plain -=== TEST 16: binary value - bytea returned in binary format +=== TEST 13: binary value - bytea returned in binary format --- http_config eval: $::http_config --- config default_type text/plain; @@ -319,7 +319,7 @@ Content-Type: text/plain -=== TEST 17: binary value - int2 returned in binary format +=== TEST 14: binary value - int2 returned in binary format --- http_config eval: $::http_config --- config default_type text/plain; @@ -340,7 +340,7 @@ Content-Type: text/plain -=== TEST 18: value - "if" pseudo-location +=== TEST 15: value - "if" pseudo-location --- http_config eval: $::http_config --- config default_type text/plain; @@ -366,7 +366,7 @@ Content-Type: text/plain -=== TEST 19: text - NULL value +=== TEST 16: text - NULL value --- http_config eval: $::http_config --- config default_type text/plain; @@ -393,7 +393,7 @@ Content-Type: text/plain -=== TEST 20: text - empty result +=== TEST 17: text - empty result --- http_config eval: $::http_config --- config default_type text/plain; @@ -414,7 +414,7 @@ Content-Type: text/plain -=== TEST 21: value - empty result +=== TEST 18: value - empty result --- http_config eval: $::http_config --- config default_type text/plain; @@ -431,7 +431,7 @@ GET /postgres -=== TEST 22: value - too many values +=== TEST 19: value - too many values --- http_config eval: $::http_config --- config default_type text/plain; diff --git a/t/sanity.t b/t/sanity.t index df9ce7b1..25c3d7ed 100644 --- a/t/sanity.t +++ b/t/sanity.t @@ -151,7 +151,6 @@ Content-Type: application/x-resty-dbd-stream --- no_error_log [alert] [error] ---- LAST diff --git a/valgrind.suppress b/valgrind.suppress index c0626772..e0b8e89d 100644 --- a/valgrind.suppress +++ b/valgrind.suppress @@ -318,4 +318,14 @@ fun:main fun:ngx_init_cycle fun:main } - +{ + + Memcheck:Cond + fun:index + fun:expand_dynamic_string_token + fun:_dl_map_object + fun:map_doit + fun:_dl_catch_error + fun:do_preload + fun:dl_main +}