| From: | "Jelte Fennema-Nio" <postgres(at)jeltef(dot)nl> |
|---|---|
| To: | "Zsolt Parragi" <zsolt(dot)parragi(at)percona(dot)com> |
| Cc: | "PostgreSQL Hackers" <pgsql-hackers(at)lists(dot)postgresql(dot)org>, "Andrey Borodin" <x4mmm(at)yandex-team(dot)ru>, "Thomas Munro" <thomas(dot)munro(at)gmail(dot)com>, "Nikolay Samokhvalov" <nik(at)postgres(dot)ai>, "Michael Paquier" <michael(at)paquier(dot)xyz>, "Jacob Champion" <jacob(dot)champion(at)enterprisedb(dot)com>, "Gregory Burd" <greg(at)burd(dot)me> |
| Subject: | Re: Reapply graceful socket shutdown on Windows (revert 29992a6a509) |
| Date: | 2026-11-26 14:10:59 |
| Message-ID: | DN57BPUHQ9QQ.2C2TBHOMC3OIU@jeltef.nl |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Thu, 8 Oct 2026 at 22:33, Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> wrote:
> On Windows, when a backend exits without closing its socket, the
> kernel does an abortive close, which resets the connection, and the
> client can lose unread data, including the FATAL message of a
> terminated backend.
Hi Zsolt and others,
I ran into this with my patch to stop libpq from appending "server
closed the connection unexpectedly" after a FATAL [1]: its postgres_fdw
test needed a Windows-only expected output because the FATAL got lost.
The graceful close is important (it's what fixes Greg's failures), but
it isn't enough to fix the problem I ran into. If the client sends
anything after the backend is gone, the server's OS (Windows or Linux)
answers with an RST and Winsock discards the unread FATAL. That's the
normal case for a FATAL on an idle connection (bug #15598 [2]), and
Alexander Lakhin hit it in 2023 too [3]. So attached is a
fix/workaround for that as well: libpq reads any pending network data
into its own buffer before sending a new query.
Attached v2, which also addresses Jacob's and Michael's concerns:
0001: Zsolt's graceful shutdown reapply, unchanged
0002: Zsolt's isolation test skip revert, rebased
0003: fixup of 0001's comment, addressing Jacob's review
0004: libpq on Windows reads pending input before sending a query on an
idle connection, plus tests
0005: POC for a server-side lingering close, which would make these
lost FATAL errors even more unlikely
P.S. A review of [1] would definitely be appreciated
[1] https://www.postgresql.org/message-id/flat/DJ60NPKYB9L9.3I3SS9I2MBL00%40jeltef.nl#3ffda50a235a05d2f3af73dbc18be18b
[2] https://www.postgresql.org/message-id/15598-e3fec9d8c5184936%40postgresql.org
[3] https://www.postgresql.org/message-id/32d112ee-0b6f-d4ab-441b-e2bba66a1d83%40gmail.com
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Reapply-graceful-shutdown-changes-for-Windows.patch | text/x-patch | 2.4 KB |
| v2-0002-Revert-Skip-isolation-tests-that-terminate-other-.patch | text/x-patch | 6.4 KB |
| v2-0003-fixup-Reapply-graceful-shutdown-changes-for-Windo.patch | text/x-patch | 2.8 KB |
| v2-0004-libpq-On-Windows-read-pending-input-before-sendin.patch | text/x-patch | 8.6 KB |
| v2-0005-POC-Add-client_connection_linger_timeout-to-avoid.patch | text/x-patch | 7.7 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Heikki Linnakangas | 2026-11-26 14:16:55 | Re: Fix two race conditions in processing interrupts |
| Previous Message | Ashutosh Bapat | 2026-11-26 13:56:09 | Re: Storing Property Graphs like Views (as a serialized analyzed parse tree) |