question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pool.connect() waits forever

See original GitHub issue

When listing the node versions, I noticed that I was forever waiting for pool.connect() to process.

import {Client, Pool} from "pg";
import * as fs from "fs";
import * as process from "process";

export interface DatabaseInterface {
    connect(): Promise<void>;

    end(): Promise<void>;

    getClient(): Promise<Client>;
}

export class Db implements DatabaseInterface {
    private client: Client;
    private pool: Pool;

    constructor() {
        const env = process.env["ENV"] || process.env.NODE_ENV || "dev";
        console.log(`DETECT ENV:: ${env}`);

        const config = JSON.parse(
            fs.readFileSync("./config/database.json", "utf-8")
        )[env];

        console.log(config)

        this.pool = new Pool(config);
    }

    async getClient(): Promise<Client> {
        return this.client;
    }

    async connect(): Promise<void> {
        this.client = await this.pool.connect();
    }

    async end(): Promise<void> {
        this.client.release();
        await this.pool.end();
    }

}

My environment is as follows. Just in case, I tried to match the pg version to 7.3.3, but the result did not change.

# Before update
Node: v8.12.0
pg: 7.3.0
# After update
Node: v12.18.3
pg: 8.3.3

The contents of console.log (config) are as follows I’m using Postgres 11.8 on AWS but I don’t think it’s a network issue as I can do the DB connection itself.

{
    "driver": "pg",
    "host": "xxxxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com",
    "database": "testdb",
    "user": "test",
    "password": "test1234",
    "port": 5432
  }

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
brianccommented, Oct 12, 2020

Yeah pg<=8.0 is not compatible with node>=14

3reactions
suryaiiitcommented, Aug 3, 2021

anyone able to fix this? or any suggestions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connection sits idle forever on PostgreSQL with Node.js and pg
const client = await pool.connect() ... i.e. it is the amount of time in milliseconds to wait when trying to get a client...
Read more >
Pooling – node-postgres
node-postgres ships with built-in connection pooling via the pg-pool module. ... all future requests to check out a client from the pool will...
Read more >
Common Reasons Why Connections Stay Open for a Long ...
Body. When you are monitoring connection pool performance, you may occasionally notice that connections are staying open for long periods of time.
Read more >
Thread waiting forever for borrowObject() cannot be interrupted
Thread waiting forever for borrowObject() cannot be interrupted. Status: ... which made the connection pool was exhausted and all of HTTP threads waiting...
Read more >
Connection Pooling in PostgresSQL with NodeJS ... - YouTube
Connection pooling is a pattern of creating a pool of available connections (usually TCP) and allow multiple clients to share the same pool...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found