postgresql/src/include
Tom Lane f3a4d7e7c2 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
2017-08-15 11:07:57 -04:00
..
access hash: Increase the number of possible overflow bitmaps by 8x. 2017-08-04 16:30:32 -04:00
bootstrap Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
catalog Teach map_partition_varattnos to handle whole-row expressions. 2017-08-03 11:21:29 -04:00
commands Final pgindent + perltidy run for v10. 2017-08-14 17:29:33 -04:00
common Update copyright in recently added files 2017-07-26 18:17:18 -04:00
datatype Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
executor Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
fe_utils Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
foreign Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
lib Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
libpq Always use 2048 bit DH parameters for OpenSSL ephemeral DH ciphers. 2017-07-31 22:36:09 +03:00
mb Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
nodes Final pgindent + perltidy run for v10. 2017-08-14 17:29:33 -04:00
optimizer Teach adjust_appendrel_attrs(_multilevel) to do multiple translations. 2017-08-15 10:49:06 -04:00
parser Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
port Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
portability Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
postmaster Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
regex Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
replication Fix replication origin-related race conditions 2017-08-08 16:07:46 -04:00
rewrite Teach map_partition_varattnos to handle whole-row expressions. 2017-08-03 11:21:29 -04:00
snowball Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
statistics Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
storage Distinguish wait-for-connection from wait-for-write-ready on Windows. 2017-08-15 11:07:57 -04:00
tcop Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
tsearch Fix serious performance problems in json(b) to_tsvector(). 2017-07-18 12:45:51 -04:00
utils Remove AtEOXact_CatCache(). 2017-08-13 16:15:14 -04:00
.gitignore Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
c.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
fmgr.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
funcapi.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
getaddrinfo.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
getopt_long.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
Makefile Add statistics subdirectory to Makefile. 2017-06-08 11:29:50 -04:00
miscadmin.h Change pg_ctl to detect server-ready by watching status in postmaster.pid. 2017-06-28 17:31:32 -04:00
pg_config.h.in Reject use of ucol_strcollUTF8() before ICU 53 2017-08-10 22:14:00 -04:00
pg_config.h.win32 Stamp HEAD as 11devel. 2017-08-14 18:08:30 -04:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_ext.h.win32 Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_manual.h Fix default minimum value for descending sequences 2017-01-23 14:00:58 -05:00
pg_getopt.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
pg_trace.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
pgstat.h Fix replication origin-related race conditions 2017-08-08 16:07:46 -04:00
pgtar.h Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
pgtime.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
port.h Change pg_ctl to detect server-ready by watching status in postmaster.pid. 2017-06-28 17:31:32 -04:00
postgres.h Phase 3 of pgindent updates. 2017-06-21 15:35:54 -04:00
postgres_ext.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
postgres_fe.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
rusagestub.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
windowapi.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00