pgsql: Attempt to fix some issues in our Windows socket code.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Attempt to fix some issues in our Windows socket code.
Date: 2012-05-13 18:35:52
Message-ID: E1STde4-00022t-Lt@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Attempt to fix some issues in our Windows socket code.

Make sure WaitLatchOrSocket regards FD_CLOSE as a read-ready condition.
We might want to tweak this further, but it was surely wrong as-is.

Make pgwin32_waitforsinglesocket detach its private event object from the
passed socket before returning. I suspect that failure to do so leads
to race conditions when other code (such as WaitLatchOrSocket) attaches
a different event object to the same socket. Moreover, the existing
coding meant that repeated calls to pgwin32_waitforsinglesocket would
perform ResetEvent on an event actively connected to a socket, which
is rumored to be an unsafe practice; the WSAEventSelect documentation
appears to recommend against this, though it does not say not to do it
in so many words.

Also, uniformly use the coding pattern "WSAEventSelect(s, NULL, 0)" to
detach events from sockets, rather than passing the event in the second
parameter. The WSAEventSelect documentation says that the second parameter
is ignored if the third is 0, so theoretically this should make no
difference. However, elsewhere on the same reference page the use of NULL
in this context is recommended, and I have found suggestions on the net
that some versions of Windows have bugs with a non-NULL second parameter
in this usage.

Some other mostly-cosmetic cleanup, such as using the right one of
WSAGetLastError and GetLastError for reporting errors from these functions.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/b85427f2276d02756b558c0024949305ea65aca5

Modified Files
--------------
src/backend/port/win32/socket.c | 44 ++++++++++++++++++++++++--------------
src/backend/port/win32_latch.c | 15 +++++++------
2 files changed, 36 insertions(+), 23 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2012-05-13 18:52:14 pgsql: Re-revert stats collector latch changes.
Previous Message Tom Lane 2012-05-13 04:31:03 pgsql: Fix bogus declaration of local variable.