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

Commit724e30c

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 parent4bd7333 commit724e30c

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
gotokeep_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
gotokeep_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
gotokeep_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
gotokeep_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
gotokeep_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
gotokeep_going;
24712489
}
24722490
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp