[COMMITTERS] pgsql: Distinguish wait-for-connection from wait-for-write-ready onWin

Поиск
Список
Период
Сортировка
От Tom Lane
Тема [COMMITTERS] pgsql: Distinguish wait-for-connection from wait-for-write-ready onWin
Дата
Msg-id E1dhdSQ-0001VF-3r@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Distinguish wait-for-connection from wait-for-write-ready on Windows.

The API for WaitLatch and friends followed the Unix convention in which
waiting for a socket connection to complete is identical to waiting for
the socket to accept a write.  While Windows provides a select(2)
emulation that agrees with that, the native WaitForMultipleObjects API
treats them as quite different --- and for some bizarre reason, it will
report a not-yet-connected socket as write-ready.  libpq itself has so
far escaped dealing with this because it waits with select(), but in
libpqwalreceiver.c we want to wait using WaitLatchOrSocket.  The semantics
mismatch resulted in replication connection failures on Windows, but only
for remote connections (apparently, localhost connections complete
immediately, or at least too fast for anyone to have noticed the problem
in single-machine testing).

To fix, introduce an additional WL_SOCKET_CONNECTED wait flag for
WaitLatchOrSocket, which is identical to WL_SOCKET_WRITEABLE on
non-Windows, but results in waiting for FD_CONNECT events on Windows.

Ideally, we would also distinguish the two conditions in the API for
PQconnectPoll(), but changing that API at this point seems infeasible.
Instead, cheat by checking for PQstatus() == CONNECTION_STARTED to
determine that we're still waiting for the connection to complete.
(This is a cheat mainly because CONNECTION_STARTED is documented as an
internal state rather than something callers should rely on.  Perhaps
we ought to change the documentation ... but this patch doesn't.)

Per reports from Jobin Augustine and Igor Neyman.  Back-patch to v10
where commit 1e8a85009 exposed this longstanding shortcoming.

Andres Freund, minor fix and some code review/beautification by me

Discussion: https://postgr.es/m/CAHBggj8g2T+ZDcACZ2FmzX9CTxkWjKBsHd6NkYB4i9Ojf6K1Fw@mail.gmail.com

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/d7ab908fbab5094e92a167441ec8d6bfb3b0c9fc

Modified Files
--------------
.../libpqwalreceiver/libpqwalreceiver.c            | 13 ++++--
src/backend/storage/ipc/latch.c                    | 50 ++++++++++++----------
src/include/storage/latch.h                        | 10 +++++
3 files changed, 47 insertions(+), 26 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: [COMMITTERS] pgsql: Teach adjust_appendrel_attrs(_multilevel) to do multipletransla
Следующее
От: Michael Meskes
Дата:
Сообщение: [COMMITTERS] pgsql: Allow continuation lines in ecpg cppline parsing.