bun icon indicating copy to clipboard operation
bun copied to clipboard

ECONNREFUSED: Failed to connect when using `node-postgres` and `postgres` packages

Open danielkaczmarczyk opened this issue 9 months ago • 2 comments

What version of Bun is running?

1.1.8+89d25807f

What platform is your computer?

Darwin 23.4.0 arm64 arm

What steps can reproduce the bug?

Create two files that attempt to connect to a pg db:

When using the postgres package:

const sql = postgres({
  // config vars here
});
const users = await sql`select * from users;`

When using node-pg:


const { Pool } = pg;
const pool = new Pool({ max: 10 });

const makeDbClientQuery = (query, client) => {
  return client.query(query[0], query[1]);
};

const extractRows = (response) => response.rows;

export const exec = async (queries) => {
  const client = await pool.connect();

  try {
    await client.query("begin");
    const responses = await Promise.all(queries.map(query => makeDbClientQuery(query, client)));
    await client.query("commit");
    return responses.map(extractRows);
  } catch (e) {
    await client.query('rollback')
    throw e;
  } finally {
    client.release();
  }
}

const res = await exec([['select * from users;', '']]);
pool.end();
console.log(res)```

## Both libraries raise the following error:

```ECONNREFUSED: Failed to connect
 syscall: "connect"

running the same code with node does not raise an error.

What is the expected behavior?

Successful connection and query execution.

What do you see instead?

 syscall: "connect"

Additional information

No response

danielkaczmarczyk avatar May 20 '24 19:05 danielkaczmarczyk