Re: Windows: Wrong error message at connection termination
Alexander Law <exclusion@gmail.com>
From: Alexander Lakhin <exclusion@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Lars Kanis <lars@greiz-reinsdorf.de>,
Thomas Munro <thomas.munro@gmail.com>,
pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2021-12-02T19:00:00Z
Lists: pgsql-hackers
Hello Tom, 29.11.2021 22:16, Tom Lane wrote: > Hm, yeah, that discussion seems to have slipped through the cracks. > Not sure why it didn't end up in pushing something. > > After re-reading that thread and re-studying relevant Windows > documentation [1][2], I think the main open question is whether > we need to issue shutdown() or not, and if so, whether to use > SD_BOTH or just SD_SEND. I'm inclined to prefer not calling > shutdown(), because [1] is self-contradictory as to whether it > can block, and [2] is pretty explicit that it's not necessary. > > regards, tom lane > > [1] https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-shutdown > [2] https://docs.microsoft.com/en-us/windows/win32/winsock/graceful-shutdown-linger-options-and-socket-closure-2 I've tested the close-only patch with pg_sleep() in pqReadData(), and it works too. So I wonder how to understand "To assure that all data is sent and received on a connected socket before it is closed, an application should use shutdown to close connection before calling closesocket." in [1]. Maybe they mean that shutdown should be used before, but not after closesocket ). Or maybe the Windows' behaviour somehow evolved over time. (With the patch I cannot reproduce the FATAL message loss even on Windows 2012 R2.) So without a practical evidence of the importance of shutdown() I'm inclined to a more simple solution too. As to 268313a95, back in 2003 it was possible to compile server on Windows only using Cygwin (though you could compile libpq with Visual C, see [3]). So "#ifdef WIN32" that is proposed now, will not affect that scenario anyway. Best regards, Alexander [3] https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=doc/src/sgml/install-win32.sgml;hb=268313a95
Commits
-
On Windows, close the client socket explicitly during backend shutdown.
- 00cd81723cd0 10.20 landed
- a87c8c3edd7f 11.15 landed
- 3e644dcca1e9 12.10 landed
- 6251f86241ac 13.6 landed
- 4cd2928543c1 14.2 landed
- 6051857fc953 15.0 landed