Permalink
Browse files

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 <piotr.sikora@frickle.com>
  • Loading branch information...
1 parent 51822ec commit 06ca0dc735e7d13274aa7ab73537740b1ffea206 @PiotrSikora PiotrSikora committed Dec 23, 2011
Showing with 5 additions and 1 deletion.
  1. +5 −1 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);

0 comments on commit 06ca0dc

Please sign in to comment.