pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedPQconsumeinput() may close the fd
4+ messages / 3 participants
[nested] [flat]
* PQconsumeinput() may close the fd
@ 2022-10-21 04:27 Vasily Kulikov <segoon@yandex-team.ru>
2022-10-21 14:18 ` Re: PQconsumeinput() may close the fd Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 1 reply; 4+ messages in thread
From: Vasily Kulikov @ 2022-10-21 04:27 UTC (permalink / raw)
To: pgsql-general
<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>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: PQconsumeinput() may close the fd
2022-10-21 04:27 PQconsumeinput() may close the fd Vasily Kulikov <segoon@yandex-team.ru>
@ 2022-10-21 14:18 ` Laurenz Albe <laurenz.albe@cybertec.at>
2022-10-21 14:40 ` Re: PQconsumeinput() may close the fd Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 4+ messages in thread
From: Laurenz Albe @ 2022-10-21 14:18 UTC (permalink / raw)
To: Vasily Kulikov <segoon@yandex-team.ru>; pgsql-general
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. Is there an error response from
the function? Perhaps something else, like a timeout in a network component,
closes the connections afterwards.
Can you find any corresponding messages in the PostgreSQL server log?
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: PQconsumeinput() may close the fd
2022-10-21 04:27 PQconsumeinput() may close the fd Vasily Kulikov <segoon@yandex-team.ru>
2022-10-21 14:18 ` Re: PQconsumeinput() may close the fd Laurenz Albe <laurenz.albe@cybertec.at>
@ 2022-10-21 14:40 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-11-01 08:09 ` Re: PQconsumeinput() may close the fd Vasily Kulikov <segoon@yandex-team.ru>
0 siblings, 1 reply; 4+ messages in thread
From: Tom Lane @ 2022-10-21 14:40 UTC (permalink / raw)
To: Laurenz Albe <laurenz.albe@cybertec.at>; +Cc: Vasily Kulikov <segoon@yandex-team.ru>; pgsql-general
Laurenz Albe <laurenz.albe@cybertec.at> 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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: PQconsumeinput() may close the fd
2022-10-21 04:27 PQconsumeinput() may close the fd Vasily Kulikov <segoon@yandex-team.ru>
2022-10-21 14:18 ` Re: PQconsumeinput() may close the fd Laurenz Albe <laurenz.albe@cybertec.at>
2022-10-21 14:40 ` Re: PQconsumeinput() may close the fd Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-11-01 08:09 ` Vasily Kulikov <segoon@yandex-team.ru>
0 siblings, 0 replies; 4+ messages in thread
From: Vasily Kulikov @ 2022-11-01 08:09 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; Laurenz Albe <laurenz.albe@cybertec.at>; +Cc: pgsql-general
<div>21.10.2022, 17:40, "Tom Lane" <tgl@sss.pgh.pa.us>:</div><blockquote><p>Laurenz Albe <<a href="mailto:laurenz.albe@cybertec.at" rel="noopener noreferrer">laurenz.albe@cybertec.at</a>> writes:</p><blockquote> On Fri, 2022-10-21 at 07:27 +0300, Vasily Kulikov wrote:<blockquote> The problem is that sometimes PQconsumeInput() may close the connection</blockquote></blockquote><p>What I'd suggest doing is checking for PQstatus(conn) == CONNECTION_BAD,<br />or else directly rechecking PQsocket() each time, rather than assuming<br />the socket is still there.</p></blockquote><div>I've chosen this one. Thanks for the help!</div>
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2022-11-01 08:09 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-10-21 04:27 PQconsumeinput() may close the fd Vasily Kulikov <segoon@yandex-team.ru>
2022-10-21 14:18 ` Laurenz Albe <laurenz.albe@cybertec.at>
2022-10-21 14:40 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-11-01 08:09 ` Vasily Kulikov <segoon@yandex-team.ru>
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