From: Sudheer H R <sudheer.hr@tekenlight.com>
To: pgsql-bugs@lists.postgresql.org
Subject: Socket (fd) to posters server getting closed. (libpq)
Date: Sun, 27 Jun 2021 19:32:06 +0530
Message-ID: <B84343DA-1078-444D-B259-A2C7C3CC6242@tekenlight.com> (raw)
Hi,
I am writing a piece of software to connect to the Postgres database in the asynchronous manner and have used PQconnectStartParams, PQsendPrepare, PQFlush , etc… in conjunction with libev.
The established connection is used for a transaction, and then added to a pool of connections, and then subsequently retrieved from the pool for reuse.
I notice that the retrieved connection has the socket fd closed, which leads to an error o the nature: could not receive data from server: Bad file descriptor
While the client library (libpq) does not detect the closed socket (unix domain socket) and tries to communicate with the server and throws an error.
Saw this communication trail on the subject https://www.postgresql.org/message-id/12708.1411394055@sss.pgh.pa.us <https://www.postgresql.org/message-id/12708.1411394055@sss.pgh.pa.us; where someone else has faced the same error while coding in python (I am using Lua for this purpose)
I guess it becomes necessary to check for readiness of read and write of the fd returned by PQsocket before continuing to use it again.
My concern is, this is happening unexpectedly and quite soon (after the connection is added to the pool in 1 or 2 seconds)
I would like to know the cause of closure of the connection, if there is any and like to arrest it rather than having to reopen the connection again.
Any feedback regarding this would be appreciated.
Regards,
Sudheer
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-bugs@postgresql.org
Cc: sudheer.hr@tekenlight.com
Subject: Re: Socket (fd) to posters server getting closed. (libpq)
In-Reply-To: <B84343DA-1078-444D-B259-A2C7C3CC6242@tekenlight.com>
References: <B84343DA-1078-444D-B259-A2C7C3CC6242@tekenlight.com>
* 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