Re: Sometimes the output to the stdout in Windows disappears

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alexander Lakhin <exclusion@gmail.com>
Cc: Victor Spirin <v.spirin@postgrespro.ru>, pgsql-hackers@lists.postgresql.org
Date: 2020-10-17T18:44:37Z
Lists: pgsql-hackers

Attachments

I wrote:
> Alexander Lakhin <exclusion@gmail.com> writes:
>> What bothers me is:
>> 	There must be a call to *WSACleanup* for each successful call to
>> 	WSAStartup
>> 	<https://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-wsastartup>.

> Yeah, that is a very odd statement.  Surely, the Windows kernel manages
> to cope if a program crashes without having done that.  So what exactly
> is the downside of intentionally not doing it?

A bit of grepping showed me that the backend, initdb, and pg_regress
all call WSAStartup without ever doing WSACleanup, and we've seen no
ill effects from that.  So it seems clear that this documentation can
safely be ignored.

I propose the attached patch.  If this doesn't cause buildfarm problems,
perhaps we should back-patch it.

BTW, I notice that libpq is asking WSAStartup for Winsock version 1.1,
which is remarkably ancient.  Almost everyplace else is asking for
version 2.2, which has been current for a decade or two.  Shouldn't
we update that?  (It occurs to me to wonder if this in itself is
some kind of problem; I wonder how well Winsock works when there are
requests for different API versions in the same program.)

			regards, tom lane

Commits

  1. In libpq for Windows, call WSAStartup once and WSACleanup not at all.

  2. Update the Winsock API version requested by libpq.