Hello. After a process termination without PQfinish() of a client, server emits the following log message not seen on Linux boxes.
> LOG: could not receive data from client: An existing connection was forcibly > closed by the remote host. This is because pgwin32_recv reuturns an error ECONNRESET for the situation instead of returning non-error EOF as recv(2) does. This patch translates WSAECONNRESET of WSARecv to an EOF so that pgwin32_recv behaves the same way with Linux. The attached patch does this. regards, -- Kyotaro Horiguchi NTT Open Source Software Center
>From 7106c56c6606af25ce65b0f5ece8dae095e7c756 Mon Sep 17 00:00:00 2001 From: Kyotaro Horiguchi <horiguchi.kyot...@lab.ntt.co.jp> Date: Thu, 2 Jun 2016 09:53:56 +0900 Subject: [PATCH] Avoid unnecessary error message on Windows On a client process termination on Windows, server emits an error message which is not seen on Linux boxes. This is caused by a difference in handling the situation by recv(). This patch translates WSACONNRESET of WSARecv to just an EOF so that the pgwin32_recv() behaves as the same with recv() on Linux. --- src/backend/port/win32/socket.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/backend/port/win32/socket.c b/src/backend/port/win32/socket.c index 5d8fb7f..9d4ac6d 100644 --- a/src/backend/port/win32/socket.c +++ b/src/backend/port/win32/socket.c @@ -372,6 +372,7 @@ pgwin32_recv(SOCKET s, char *buf, int len, int f) DWORD b; DWORD flags = f; int n; + int lasterror; if (pgwin32_poll_signals()) return -1; @@ -383,7 +384,13 @@ pgwin32_recv(SOCKET s, char *buf, int len, int f) if (r != SOCKET_ERROR) return b; /* success */ - if (WSAGetLastError() != WSAEWOULDBLOCK) + lasterror = WSAGetLastError(); + + /* Unix's recv treats a connection reset by peer as just an EOF */ + if (lasterror == WSAECONNRESET) + return 0; + + if (lasterror != WSAEWOULDBLOCK) { TranslateSocketError(); return -1; @@ -410,7 +417,14 @@ pgwin32_recv(SOCKET s, char *buf, int len, int f) r = WSARecv(s, &wbuf, 1, &b, &flags, NULL, NULL); if (r != SOCKET_ERROR) return b; /* success */ - if (WSAGetLastError() != WSAEWOULDBLOCK) + + lasterror = WSAGetLastError(); + + /* Unix's recv treats a connection reset by peer as just an EOF */ + if (lasterror == WSAECONNRESET) + return 0; + + if (lasterror != WSAEWOULDBLOCK) { TranslateSocketError(); return -1; -- 1.8.3.1
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers