Skip to content

Pool config: idleTimeoutMillis documentation #1892

Description

@jamesmbourne

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions