Skip to content

Commit

Permalink
Make sure that the write event really occured before re-polling.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
PiotrSikora committed Dec 23, 2011
1 parent 51822ec commit 06ca0dc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ngx_postgres_processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 06ca0dc

Please sign in to comment.