I have been experiencing issues with using a Pool and receiving the following error:
Error: Client was closed and is not queryable
Library version: pg@7.10.0
This has been occuring when a long-running operation takes place between 2 DB queries e.g:
const pool = new Pool();
const sleep = (milliseconds: number) =>
new Promise(resolve => setTimeout(resolve, milliseconds));
pool.connect(async (err, client, release) => {
await db.query('SELECT 1');
// SOME LONG RUNNING OPERATION
await sleep(15000);
// Error thrown here as client has been disconnected
await db.query('SELECT 1');
release();
});
This seems to be caused by the idleTimeoutMillis configuration parameter for the Pool. The documentation states that this timeout is how long "a client must sit idle in the pool and not be checked out" before it is disconnected and discarded.
In the example above, the client is not returned to the pool unit release() is called, yet it is not available by the time the second db.query is called.
Is this behaviour expexcted? If so, it may be something to clarify in the documentation as my understanding was that this timeout would only apply to clients sat in the pool, not ones currently acquired and in use.
I have been experiencing issues with using a Pool and receiving the following error:
Library version:
pg@7.10.0This has been occuring when a long-running operation takes place between 2 DB queries e.g:
This seems to be caused by the
idleTimeoutMillisconfiguration parameter for thePool. The documentation states that this timeout is how long "a client must sit idle in the pool and not be checked out" before it is disconnected and discarded.In the example above, the client is not returned to the pool unit
release()is called, yet it is not available by the time the seconddb.queryis called.Is this behaviour expexcted? If so, it may be something to clarify in the documentation as my understanding was that this timeout would only apply to clients sat in the pool, not ones currently acquired and in use.