On 10/16/20 12:18 PM, Tom Lane wrote: > > But wait a minute: I just looked at Microsoft's docs [1] and found > > In a multithreaded environment, WSACleanup terminates Windows Sockets > operations for all threads. > > This makes me (a) wonder if that explains the side-effects on stdio, > and (b) question why libpq is calling WSACleanup at all. > What if we arranged to call WSAStartup just once, during the first > libpq connection-open in a process, and then never did WSACleanup? > Surely the OS can cope with that, and it eliminates any risk that > WSACleanup breaks something. > > regards, tom lane > > [1] > https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-wsacleanup > >
This could explain random transient stdout/stderr failures we have seen over the years. I think we should at least give your suggestion a try - this is a good time in the dev cycle for such experiments. cheers andrew