Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 724e30c

Browse files
committed
Ensure we discard unread/unsent data when abandoning a connection attempt.
There are assorted situations wherein PQconnectPoll() will abandon a connection attempt and try again with different parameters (eg, SSL versus not SSL). However, the code forgot to discard any pending data in libpq's I/O buffers when doing this. In at least one case (server returns E message during SSL negotiation), there is unread input data which bollixes the next connection attempt. I have not checked to see whether this is possible in the other cases where we close the socket and retry, but it seems like a matter of good defensive programming to add explicit buffer-flushing code to all of them. This is one of several issues exposed by Daniel Farina's report of misbehavior after a server-side fork failure. This has been wrong since forever, so back-patch to all supported branches.
1 parent 4bd7333 commit 724e30c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,6 +2068,9 @@ PQconnectPoll(PGconn *conn)
20682068
closesocket(conn->sock);
20692069
conn->sock = -1;
20702070
conn->status = CONNECTION_NEEDED;
2071+
/* Discard any unread/unsent data */
2072+
conn->inStart = conn->inCursor = conn->inEnd = 0;
2073+
conn->outCount = 0;
20712074
goto keep_going;
20722075
}
20732076
else
@@ -2105,6 +2108,9 @@ PQconnectPoll(PGconn *conn)
21052108
closesocket(conn->sock);
21062109
conn->sock = -1;
21072110
conn->status = CONNECTION_NEEDED;
2111+
/* Discard any unread/unsent data */
2112+
conn->inStart = conn->inCursor = conn->inEnd = 0;
2113+
conn->outCount = 0;
21082114
goto keep_going;
21092115
}
21102116
}
@@ -2218,6 +2224,9 @@ PQconnectPoll(PGconn *conn)
22182224
closesocket(conn->sock);
22192225
conn->sock = -1;
22202226
conn->status = CONNECTION_NEEDED;
2227+
/* Discard any unread/unsent data */
2228+
conn->inStart = conn->inCursor = conn->inEnd = 0;
2229+
conn->outCount = 0;
22212230
goto keep_going;
22222231
}
22232232

@@ -2285,6 +2294,9 @@ PQconnectPoll(PGconn *conn)
22852294
closesocket(conn->sock);
22862295
conn->sock = -1;
22872296
conn->status = CONNECTION_NEEDED;
2297+
/* Discard any unread/unsent data */
2298+
conn->inStart = conn->inCursor = conn->inEnd = 0;
2299+
conn->outCount = 0;
22882300
goto keep_going;
22892301
}
22902302

@@ -2304,6 +2316,9 @@ PQconnectPoll(PGconn *conn)
23042316
closesocket(conn->sock);
23052317
conn->sock = -1;
23062318
conn->status = CONNECTION_NEEDED;
2319+
/* Discard any unread/unsent data */
2320+
conn->inStart = conn->inCursor = conn->inEnd = 0;
2321+
conn->outCount = 0;
23072322
goto keep_going;
23082323
}
23092324
#endif
@@ -2467,6 +2482,9 @@ PQconnectPoll(PGconn *conn)
24672482
closesocket(conn->sock);
24682483
conn->sock = -1;
24692484
conn->status = CONNECTION_NEEDED;
2485+
/* Discard any unread/unsent data */
2486+
conn->inStart = conn->inCursor = conn->inEnd = 0;
2487+
conn->outCount = 0;
24702488
goto keep_going;
24712489
}
24722490
}

0 commit comments

Comments
 (0)