Socket (fd) to posters server getting closed. (libpq)

From: Sudheer H R <sudheer(dot)hr(at)tekenlight(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Socket (fd) to posters server getting closed. (libpq)
Date: 2021-06-27 14:02:06
Message-ID: B84343DA-1078-444D-B259-A2C7C3CC6242@tekenlight.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2021-06-27 14:12:38 Re: Socket (fd) to posters server getting closed. (libpq)
Previous Message Michael Paquier 2021-06-27 01:35:49 Re: Assertion on create index concurrently