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 1olmPw-0001oD-79 for pgsql-general@arkaria.postgresql.org; Fri, 21 Oct 2022 07:26:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1olmPv-0000NL-6v for pgsql-general@arkaria.postgresql.org; Fri, 21 Oct 2022 07:26:07 +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 1oljdb-0003rZ-RG for pgsql-general@lists.postgresql.org; Fri, 21 Oct 2022 04:28:03 +0000 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oljdZ-0000Gz-Bl for pgsql-general@postgresql.org; Fri, 21 Oct 2022 04:28:03 +0000 Received: from vla1-f615dbed14ca.qloud-c.yandex.net (vla1-f615dbed14ca.qloud-c.yandex.net [IPv6:2a02:6b8:c0d:3183:0:640:f615:dbed]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTP id 2AF1C600DC for ; Fri, 21 Oct 2022 07:27:49 +0300 (MSK) Received: from mail.yandex-team.ru (mail.yandex-team.ru [2a02:6b8:b081:b526::1:23]) by vla1-f615dbed14ca.qloud-c.yandex.net (mxbackcorp/Yandex) with HTTP id fQaKp204ia61-Rn4m1jeu; Fri, 21 Oct 2022 07:27:49 +0300 X-Yandex-Fwd: 2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1666326469; bh=cbGbVOb96v84kf4G/t1ohLl566EKOJsaoQfgx5XTgGs=; h=Date:Subject:To:From:Message-Id; b=MVbi0JJanxoUE04NaRpvtFxk/ahpG0vf+xkCV8johX5zUGUEIk1X8bYfiHikA3V76 INDFcYfsm/aThR/Q2MOfsjbE2q44MFBEGOW+j5yvoPFzPKzxCCAoXJ42v0oVj5qaD+ 6tmnNrDSKlRVrPjoXdWNF1IaJXOOnH5QAEEr7PoA= Authentication-Results: vla1-f615dbed14ca.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from mejgq6zk2vrbiq2h.sas.yp-c.yandex.net (mejgq6zk2vrbiq2h.sas.yp-c.yandex.net [2a02:6b8:c14:2791:0:640:4704:0]) by sas1-9c28cd37d27b.qloud-c.yandex.net (mxbackcorp/Yandex) with HTTP id 1RaXR403ra61-mQS46eUr for ; Fri, 21 Oct 2022 07:27:39 +0300 Received: by mejgq6zk2vrbiq2h.sas.yp-c.yandex.net with HTTP; Fri, 21 Oct 2022 07:27:38 +0300 From: Vasily Kulikov To: "pgsql-general@postgresql.org" Subject: PQconsumeinput() may close the fd MIME-Version: 1.0 X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Fri, 21 Oct 2022 07:27:48 +0300 Message-Id: <53811666325878@mail.yandex-team.ru> Content-Transfer-Encoding: 8bit Content-Type: text/html; charset=utf-8 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk
Hello,
 
There is an event loop in my program (libev) and I do PQconsumeInput() if there is something ready in the PG socket fd. The problem is that sometimes PQconsumeInput() may close the connection and I learn it by checking for PQsocket() afterwards only. AFAICS, there is no way to learn it beforehand. The core issue is that I have to deregister socket fd in the event loop, but the fd is already closed. It is already not good because we're still working with already invalid fd, but worse, in multithreaded env other thread might open a socket with the same fd number and mess all the things.
 
So, what to do in this case? Should I use other API that may not close fd? Or only select/poll API may be used with every time fd registration, but not epoll? Or maybe I'm wrong in some other way?
 
Thanks in advance.