Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQWGW-0001dm-UW for pgsql-committers@arkaria.postgresql.org; Thu, 08 Oct 2020 13:47:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kQWGV-00026r-HS for pgsql-committers@arkaria.postgresql.org; Thu, 08 Oct 2020 13:47:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQWGV-00026j-CB for pgsql-committers@lists.postgresql.org; Thu, 08 Oct 2020 13:47:27 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQWGS-0006TL-AZ for pgsql-committers@lists.postgresql.org; Thu, 08 Oct 2020 13:47:27 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 098DlKPl2461601; Thu, 8 Oct 2020 09:47:20 -0400 From: Tom Lane To: Fujii Masao cc: Michael Paquier , Fujii Masao , pgsql-committers@lists.postgresql.org Subject: Re: pgsql: postgres_fdw: reestablish new connection if cached one is detect In-reply-to: References: <20201007021347.GD2256@paquier.xyz> <14cd32c8-9532-47b8-77d4-b81eb3b192ea@oss.nttdata.com> <78d509fe-f87a-7046-672a-f86cb6f6957d@oss.nttdata.com> Comments: In-reply-to Fujii Masao message dated "Thu, 08 Oct 2020 12:43:17 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2461599.1602164840.1@sss.pgh.pa.us> Date: Thu, 08 Oct 2020 09:47:20 -0400 Message-ID: <2461600.1602164840@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Fujii Masao writes: >> Therefore, the easy fix is to make libpq mark the connection as >> CONNECTION_BAD even in ECONNABORTED, like we do in ECONNRESET. > Patch attached. This patch also changes errcode_for_socket_access() > so that it uses ERRCODE_CONNECTION_FAILURE rather than > ERRCODE_INTERNAL_ERROR as sqlerrorcode in ECONNABORTED case > like ECONNRESET. Is this sane? Some digging around on the net suggests that Windows will only return WSAECONNRESET for the case where it gets a TCP RST packet from the remote host. Other cases of TCP connection loss (e.g. timeout) are reported as WSAECONNABORTED. I think that our code generally only expects ECONNRESET to be reported for a lost connection. Based on this info, we clearly need to handle ECONNABORTED as being equivalent to that. I don't see any reason why we'd care to distinguish the two cases. So it seems like (a) we'd better make sure that ECONNABORTED is recognized anyplace that we're testing for ECONNRESET, and (b) that seems like a back-patchable bug fix, independently of the immediate issue. On the other hand, it seems a bit odd that we've not recognized this issue long since. Maybe the preference for ECONNABORTED only exists on a few Windows versions? I've not checked your patch in detail. regards, tom lane