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

Commitb5dd50f

Browse files
committed
Rewrite async-connection loop in libpqwalreceiver.c, once again.
The original coding in commit1e8a850 didn't use PQconnectPoll perspec, and while the rewrite ine434ad3 is closer, it still doesn'tguarantee to wait until the socket is read-ready or write-ready (asappropriate) before calling PQconnectPoll. It's not clear whetherthat omission is causing the continuing failures on buildfarm memberbowerbird; but given the lack of other explanations meeting theavailable facts, let's tighten that up and see what happens.An independent issue in the same loop was that it had a race conditionwhereby it could clear the process's latch without having serviced aninterrupt request, causing failure to respond to a cancel while waitingfor connection (the very problem1e8a850 was meant to fix).Discussion:https://postgr.es/m/7295.1489596949@sss.pgh.pa.us
1 parent1ea60ad commitb5dd50f

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

‎src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -159,41 +159,41 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
159159
/*
160160
* Poll connection until we have OK or FAILED status.
161161
*
162-
* Note that the initial state after PQconnectStartParams is
163-
* PGRES_POLLING_WRITING.
162+
* Per spec for PQconnectPoll, first wait till socket is write-ready.
164163
*/
165-
for (status=PGRES_POLLING_WRITING;
166-
status!=PGRES_POLLING_OK&&status!=PGRES_POLLING_FAILED;
167-
status=PQconnectPoll(conn->streamConn))
164+
status=PGRES_POLLING_WRITING;
165+
do
168166
{
169-
/* Sleep a bit if waiting for socket. */
170-
if (status==PGRES_POLLING_READING||
171-
status==PGRES_POLLING_WRITING)
167+
/* Wait for socket ready and/or other events. */
168+
intio_flag;
169+
intrc;
170+
171+
io_flag= (status==PGRES_POLLING_READING
172+
?WL_SOCKET_READABLE
173+
:WL_SOCKET_WRITEABLE);
174+
175+
rc=WaitLatchOrSocket(&MyProc->procLatch,
176+
WL_POSTMASTER_DEATH |
177+
WL_LATCH_SET |io_flag,
178+
PQsocket(conn->streamConn),
179+
0,
180+
WAIT_EVENT_LIBPQWALRECEIVER);
181+
182+
/* Emergency bailout? */
183+
if (rc&WL_POSTMASTER_DEATH)
184+
exit(1);
185+
186+
/* Interrupted? */
187+
if (rc&WL_LATCH_SET)
172188
{
173-
intextra_flag;
174-
intrc;
175-
176-
extra_flag= (status==PGRES_POLLING_READING
177-
?WL_SOCKET_READABLE
178-
:WL_SOCKET_WRITEABLE);
179-
180189
ResetLatch(&MyProc->procLatch);
181-
rc=WaitLatchOrSocket(&MyProc->procLatch,
182-
WL_POSTMASTER_DEATH |
183-
WL_LATCH_SET |extra_flag,
184-
PQsocket(conn->streamConn),
185-
0,
186-
WAIT_EVENT_LIBPQWALRECEIVER);
187-
188-
/* Emergency bailout. */
189-
if (rc&WL_POSTMASTER_DEATH)
190-
exit(1);
191-
192-
/* Interrupted. */
193-
if (rc&WL_LATCH_SET)
194-
CHECK_FOR_INTERRUPTS();
190+
CHECK_FOR_INTERRUPTS();
195191
}
196-
}
192+
193+
/* If socket is ready, advance the libpq state machine */
194+
if (rc&io_flag)
195+
status=PQconnectPoll(conn->streamConn);
196+
}while (status!=PGRES_POLLING_OK&&status!=PGRES_POLLING_FAILED);
197197

198198
if (PQstatus(conn->streamConn)!=CONNECTION_OK)
199199
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp