From 7d00a6b2de8ab1e95e052663064defb0bc3022f6 Mon Sep 17 00:00:00 2001
From: Tom Lane
Date: Sat, 17 Oct 2020 16:53:48 -0400
Subject: In libpq for Windows, call WSAStartup once and WSACleanup not at all.
The Windows documentation insists that every WSAStartup call should
have a matching WSACleanup call. However, if that ever had actual
relevance, it wasn't in this century. Every remotely-modern Windows
kernel is capable of cleaning up when a process exits without doing
that, and must be so to avoid resource leaks in case of a process
crash. Moreover, Postgres backends have done WSAStartup without
WSACleanup since commit 4cdf51e64 in 2004, and we've never seen any
indication of a problem with that.
libpq's habit of doing WSAStartup during connection start and
WSACleanup during shutdown is also rather inefficient, since a
series of non-overlapping connection requests leads to repeated,
quite expensive DLL unload/reload cycles. We document a workaround
for that (having the application call WSAStartup for itself), but
that's just a kluge. It's also worth noting that it's far from
uncommon for applications to exit without doing PQfinish, and
we've not heard reports of trouble from that either.
However, the real reason for acting on this is that recent
experiments by Alexander Lakhin suggest that calling WSACleanup
during PQfinish might be triggering the symptom we occasionally see
that a process using libpq fails to emit expected stdio output.
Therefore, let's change libpq so that it calls WSAStartup only
once per process, during the first connection attempt, and never
calls WSACleanup at all.
While at it, get rid of the only other WSACleanup call in our code
tree, in pg_dump/parallel.c; that presumably is equally useless.
If this proves to suppress the fairly-common ecpg test failures
we see on Windows, I'll back-patch, but for now let's just do it
in HEAD and see what happens.
Discussion: https://postgr.es/m/ac976d8c-03df-d6b8-025c-15a2de8d9af1@postgrespro.ru
---
doc/src/sgml/libpq.sgml | 15 ---------------
1 file changed, 15 deletions(-)
(limited to 'doc/src')
diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml
index 3315f1dd05b..de60281fcb4 100644
--- a/doc/src/sgml/libpq.sgml
+++ b/doc/src/sgml/libpq.sgml
@@ -91,21 +91,6 @@
-
-
- On Windows, there is a way to improve performance if a single
- database connection is repeatedly started and shutdown. Internally,
- libpq calls WSAStartup() and WSACleanup() for connection startup
- and shutdown, respectively. WSAStartup() increments an internal
- Windows library reference count which is decremented by WSACleanup().
- When the reference count is just one, calling WSACleanup() frees
- all resources and all DLLs are unloaded. This is an expensive
- operation. To avoid this, an application can manually call
- WSAStartup() so resources will not be freed when the last database
- connection is closed.
-
-
-
PQconnectdbParamsPQconnectdbParams
--
cgit v1.2.3