Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit431b638

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

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
@@ -1911,6 +1911,9 @@ PQconnectPoll(PGconn *conn)
19111911
closesocket(conn->sock);
19121912
conn->sock=-1;
19131913
conn->status=CONNECTION_NEEDED;
1914+
/* Discard any unread/unsent data */
1915+
conn->inStart=conn->inCursor=conn->inEnd=0;
1916+
conn->outCount=0;
19141917
gotokeep_going;
19151918
}
19161919
else
@@ -1948,6 +1951,9 @@ PQconnectPoll(PGconn *conn)
19481951
closesocket(conn->sock);
19491952
conn->sock=-1;
19501953
conn->status=CONNECTION_NEEDED;
1954+
/* Discard any unread/unsent data */
1955+
conn->inStart=conn->inCursor=conn->inEnd=0;
1956+
conn->outCount=0;
19511957
gotokeep_going;
19521958
}
19531959
}
@@ -2061,6 +2067,9 @@ PQconnectPoll(PGconn *conn)
20612067
closesocket(conn->sock);
20622068
conn->sock=-1;
20632069
conn->status=CONNECTION_NEEDED;
2070+
/* Discard any unread/unsent data */
2071+
conn->inStart=conn->inCursor=conn->inEnd=0;
2072+
conn->outCount=0;
20642073
gotokeep_going;
20652074
}
20662075

@@ -2128,6 +2137,9 @@ PQconnectPoll(PGconn *conn)
21282137
closesocket(conn->sock);
21292138
conn->sock=-1;
21302139
conn->status=CONNECTION_NEEDED;
2140+
/* Discard any unread/unsent data */
2141+
conn->inStart=conn->inCursor=conn->inEnd=0;
2142+
conn->outCount=0;
21312143
gotokeep_going;
21322144
}
21332145

@@ -2147,6 +2159,9 @@ PQconnectPoll(PGconn *conn)
21472159
closesocket(conn->sock);
21482160
conn->sock=-1;
21492161
conn->status=CONNECTION_NEEDED;
2162+
/* Discard any unread/unsent data */
2163+
conn->inStart=conn->inCursor=conn->inEnd=0;
2164+
conn->outCount=0;
21502165
gotokeep_going;
21512166
}
21522167
#endif
@@ -2308,6 +2323,9 @@ PQconnectPoll(PGconn *conn)
23082323
closesocket(conn->sock);
23092324
conn->sock=-1;
23102325
conn->status=CONNECTION_NEEDED;
2326+
/* Discard any unread/unsent data */
2327+
conn->inStart=conn->inCursor=conn->inEnd=0;
2328+
conn->outCount=0;
23112329
gotokeep_going;
23122330
}
23132331
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp