pool.connect() waits forever
See original GitHub issueWhen 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:
- Created 3 years ago
- Reactions:2
- Comments:11 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah pg<=8.0 is not compatible with node>=14
anyone able to fix this? or any suggestions.