From 06ca0dc735e7d13274aa7ab73537740b1ffea206 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Fri, 23 Dec 2011 19:07:54 +0000 Subject: [PATCH] Make sure that the write event really occured before re-polling. The "re-polling" hack to work-around the case in which both: read and write events occured within the same event processing call was being used for any CONNECTION_MADE status, without checking if the write really occured. Based on patch from Yichun Zhang (agentzh). Change-Id: Ia8310a109baf639d1c5c3c766d2298c3610e6d47 Signed-off-by: Piotr Sikora --- src/ngx_postgres_processor.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ngx_postgres_processor.c b/src/ngx_postgres_processor.c index 0f431550..f91852b8 100644 --- a/src/ngx_postgres_processor.c +++ b/src/ngx_postgres_processor.c @@ -128,16 +128,19 @@ ngx_postgres_upstream_connect(ngx_http_request_t *r, ngx_connection_t *pgxc, * writable event that has already appeared and will never appear * again :)" */ - if (PQstatus(pgdt->pgconn) == CONNECTION_MADE) { + if (PQstatus(pgdt->pgconn) == CONNECTION_MADE && pgxc->write->ready) { dd("re-polling on connection made"); pgrc = PQconnectPoll(pgdt->pgconn); + dd("re-polling rc:%d", (int) pgrc); if (pgrc == PGRES_POLLING_READING || pgrc == PGRES_POLLING_WRITING) { dd("returning NGX_AGAIN"); return NGX_AGAIN; } + + goto done; } #if defined(DDEBUG) && (DDEBUG) @@ -179,6 +182,7 @@ ngx_postgres_upstream_connect(ngx_http_request_t *r, ngx_connection_t *pgxc, return NGX_AGAIN; } +done: /* remove connection timeout from new connection */ if (pgxc->write->timer_set) { ngx_del_timer(pgxc->write);