Skip to content

Commit 06ca0dc

Browse files
committed
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 <[email protected]>
1 parent 51822ec commit 06ca0dc

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/ngx_postgres_processor.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,19 @@ ngx_postgres_upstream_connect(ngx_http_request_t *r, ngx_connection_t *pgxc,
128128
* writable event that has already appeared and will never appear
129129
* again :)"
130130
*/
131-
if (PQstatus(pgdt->pgconn) == CONNECTION_MADE) {
131+
if (PQstatus(pgdt->pgconn) == CONNECTION_MADE && pgxc->write->ready) {
132132
dd("re-polling on connection made");
133133

134134
pgrc = PQconnectPoll(pgdt->pgconn);
135+
dd("re-polling rc:%d", (int) pgrc);
135136

136137
if (pgrc == PGRES_POLLING_READING || pgrc == PGRES_POLLING_WRITING)
137138
{
138139
dd("returning NGX_AGAIN");
139140
return NGX_AGAIN;
140141
}
142+
143+
goto done;
141144
}
142145

143146
#if defined(DDEBUG) && (DDEBUG)
@@ -179,6 +182,7 @@ ngx_postgres_upstream_connect(ngx_http_request_t *r, ngx_connection_t *pgxc,
179182
return NGX_AGAIN;
180183
}
181184

185+
done:
182186
/* remove connection timeout from new connection */
183187
if (pgxc->write->timer_set) {
184188
ngx_del_timer(pgxc->write);

0 commit comments

Comments
 (0)