Skip to content
This repository was archived by the owner on Dec 30, 2019. It is now read-only.
This repository was archived by the owner on Dec 30, 2019. It is now read-only.

Connection terminated due to connection timeout / Connection terminated #116

@dustin-H

Description

@dustin-H

Hi there,

I got some issues with this pool.
Maybe this is related to brianc/node-postgres#1790 and brianc/node-postgres#1611.

First of all this is my environment:

  • node-postgres@7.7.1
  • pg-pool@2.0.5
  • NodeJS v10.15.0
  • PostgreSQL 10.6 (hosted by Aiven.io [50 connections])

I'm using pg-pool with this config:

{
   /* normal credentials with ssl */
   min: 10,
   max: 46,
   idleTimeoutMillis: 30000,
   connectionTimeoutMillis:  3000
}

I get about 10 times a day this error:
Connection terminated due to connection timeout.

This leads to a failure of some query and thus to an error for the end-user.

I already tried to debug this in cooperation with my Database-Provider, however this doesn't seem to be related to that. The ping to my db is about 0.23ms in the same data-center.

After having a look at the code, enabling detailed logging and hours of debugging I think I found the issue.

I think this is related to ending clients on idle timeouts:
https://github.com/brianc/node-pg-pool/blob/master/index.js#L41

Here the idle timeout is triggered, however it does not check if the client is currently used. I know the timeout is cleared in https://github.com/brianc/node-pg-pool/blob/master/index.js#L138, but there seems to be an edge case where a client gets destroyed, which has just been given to the application.

For me that happened once in about 2000 requests.

To prove my intention, I set idleTimeoutMillis to 0, which disables the removal of idle clients. This solved the issue for me. I never got this error again.

I cannot really say how this can happen nor how to fix it, but I'm pretty sure this is related to the idle-timeout.

Hope this helps debugging it.

Have a nice day,
Dustin

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