21.10.2022, 17:40, "Tom Lane" <tgl@sss.pgh.pa.us>:

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

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.

I've chosen this one. Thanks for the help!