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 1oltCN-0003RK-D0 for pgsql-general@arkaria.postgresql.org; Fri, 21 Oct 2022 14:40:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oltCL-0004bW-Cw for pgsql-general@arkaria.postgresql.org; Fri, 21 Oct 2022 14:40:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oltCK-0004ah-Ty for pgsql-general@lists.postgresql.org; Fri, 21 Oct 2022 14:40:32 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oltCI-0003xR-Se for pgsql-general@postgresql.org; Fri, 21 Oct 2022 14:40:31 +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 29LEeSSO3198035; Fri, 21 Oct 2022 10:40:28 -0400 From: Tom Lane To: Laurenz Albe cc: Vasily Kulikov , "pgsql-general@postgresql.org" Subject: Re: PQconsumeinput() may close the fd In-reply-to: <7e60d1a4a536a12fdd1c15caae93bac79b0ab8b1.camel@cybertec.at> References: <53811666325878@mail.yandex-team.ru> <7e60d1a4a536a12fdd1c15caae93bac79b0ab8b1.camel@cybertec.at> Comments: In-reply-to Laurenz Albe message dated "Fri, 21 Oct 2022 16:18:59 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3198033.1666363228.1@sss.pgh.pa.us> Date: Fri, 21 Oct 2022 10:40:28 -0400 Message-ID: <3198034.1666363228@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Laurenz Albe writes: > On Fri, 2022-10-21 at 07:27 +0300, Vasily Kulikov wrote: >> The problem is that sometimes PQconsumeInput() may close the connection > The function does nothing of the kind. No, he's right: if we detect EOF then we'll close the socket. However, not doing so wouldn't be an improvement. I believe the socket would still be read-ready so you'd have an infinite loop. What I'd suggest doing is checking for PQstatus(conn) == CONNECTION_BAD, or else directly rechecking PQsocket() each time, rather than assuming the socket is still there. regards, tom lane