node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

Node v17 ECONNREFUSED

Open KhafraDev opened this issue 3 years ago • 4 comments

Description

On node v16.13.0, connecting to the database works as expected. I decided to try out the changes in v17.0.1 and I can't connect to the db anymore.

Test script:

import pg from 'pg';

export const pool = new pg.Pool({
    user: process.env.POSTGRES_USER,
    password: process.env.POSTGRES_PASS,
    database: 'kb'
});

console.log(process.version);
pool.query(`SELECT NOW()`).then(({ rows }) => console.log(rows[0]));

Output (both versions)

pg>node test
v16.13.0
{ now: 2021-10-29T18:14:27.011Z }
pg>node test
v17.0.1
node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

Error: connect ECONNREFUSED ::1:5432
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
  errno: -4078,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 5432
}

Node.js v17.0.1

Environment

Windows 10, running postgres from WSL 2

KhafraDev avatar Oct 29 '21 18:10 KhafraDev

What does your postgresql.conf file say for listen_addresses?

treysis avatar Nov 13 '21 00:11 treysis

commented out, unchanged from install

KhafraDev avatar Nov 21 '21 03:11 KhafraDev

@KhafraDev Try changing it to listen_addresses = '127.0.0.1,::1' and see if that works?

treysis avatar Nov 21 '21 15:11 treysis

I'm having the same issue with listen_addresses = '*' and running on docker for mac. I assume https://github.com/docker/for-mac/issues/1432 could be the issue here.

marcbachmann avatar Dec 28 '21 21:12 marcbachmann

@marcbachmann is your code running in a container and your DB running in another?

thoroc avatar Oct 18 '22 15:10 thoroc

Sorry, I'm not sure what the issue was anymore. I was able to upgrade later and everything is running on node 18. Usually we have node outside docker, directly on the mac host, and then postgres within docker. Maybe I posted the comment above when I was trying to run it within our CI or on macos, therefore completely in docker. I can report back here in case it's still failing as I'll upgrade to node 18 within the next 2 weeks.

marcbachmann avatar Oct 18 '22 15:10 marcbachmann