From: Vasily Kulikov <segoon@yandex-team.ru>
To: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: PQconsumeinput() may close the fd
Date: Fri, 21 Oct 2022 07:27:48 +0300
Message-ID: <53811666325878@mail.yandex-team.ru> (raw)
<div>Hello,</div><div> </div><div>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.</div><div> </div><div>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?</div><div> </div><div>Thanks in advance.</div>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: segoon@yandex-team.ru
Subject: Re: PQconsumeinput() may close the fd
In-Reply-To: <53811666325878@mail.yandex-team.ru>
References: <53811666325878@mail.yandex-team.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox