Skip to content

client in pool timed out, causing pool to fail for all future queries #2243

Description

@isaacl

Hello! I'm using a pg-pool in a lambda environment. Last night, the pool hit an error:

2020-06-19T17:28:50.154-04:00 | START
2020-06-19T17:28:50.257-04:00 | ERROR	Invoke Error
"Error: Connection terminated due to connection timeout",
        "    at Timeout.<anonymous> (/var/task/node_modules/pg/lib/client.js:103:26)",

My pool is a static global to allow lambda to reuse across invocations. I guess pg wasn't smart enough to check idle timeout before assigning a client, and in this case it was already dead – is there a way to flush the pool on each lambda invocation startup?

Anyway, somehow this first timeout put the pool in a bad state, and every call to the pool (which are made using the .query helper) instantly failed with a timeout.

  | 2020-06-19T17:29:17.492-04:00 | START
  | 2020-06-19T17:29:17.496-04:00 | ERROR	Invoke Error
Error: Connection terminated due to connection timeout

My config (pg 8.0.3, xray 3.0.1)

import pg from 'pg';
import xrayPostgres from 'aws-xray-sdk-postgres';
const { Pool } = xrayPostgres(pg)
const pool = new Pool({
      connectionTimeoutMillis: 5000,
      idleTimeoutMillis: 60000,
      ssl: ...
});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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