Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This does not work with node 20 #91

Open
dmitryame opened this issue Jan 8, 2024 · 12 comments
Open

This does not work with node 20 #91

dmitryame opened this issue Jan 8, 2024 · 12 comments
Assignees
Labels
bug Something isn't working

Comments

@dmitryame
Copy link

on the first attempt i get error:
self-signed certificate in certificate chain

There after it just silently fails on making a call to a database.

The same code works perfectly fine from node 18 in aws lambda environment, but if I deploy the same code as node 20 -- database stops working.

@heythisischris
Copy link

heythisischris commented Jan 9, 2024

on the first attempt i get error:

self-signed certificate in certificate chain

There after it just silently fails on making a call to a database.

The same code works perfectly fine from node 18 in aws lambda environment, but if I deploy the same code as node 20 -- database stops working.

A simple fix for this is adding NODE_TLS_REJECT_UNAUTHORIZED as an environment variable and setting it to 0.

@dmitryame
Copy link
Author

dmitryame commented Jan 9, 2024 via email

@heythisischris
Copy link

No problem!

@MatteoGioioso
Copy link
Owner

MatteoGioioso commented Apr 12, 2024

@dmitryame Sorry for the extremely late reply. Is this still a problem? NODE_TLS_REJECT_UNAUTHORIZED=0 is not the best if you want to run in production. I can push a fix as soon as I have time.

@MatteoGioioso MatteoGioioso self-assigned this Apr 12, 2024
@MatteoGioioso MatteoGioioso added the bug Something isn't working label Apr 12, 2024
@dmitryame
Copy link
Author

dmitryame commented Apr 12, 2024 via email

@MatteoGioioso
Copy link
Owner

MatteoGioioso commented Apr 16, 2024

@dmitryame sure, I will push a patch latest tomorrow, if I can find a way to fix it

@dmitryame
Copy link
Author

dmitryame commented Apr 16, 2024 via email

@MatteoGioioso
Copy link
Owner

MatteoGioioso commented Apr 17, 2024

Hello again,
unfortunately I have realized that this could be tricky to test. On my machine with node v20 the tests run without errors.
I have just updated all the dependencies, in the hope this will fix your problem, now is using pg: 8.11.5.

If the problem persists try to open an issue on node-pg: https://github.com/brianc/node-postgres

New version should be up: v2.1.1

@dmitryame
Copy link
Author

dmitryame commented Apr 17, 2024 via email

@MatteoGioioso
Copy link
Owner

Dammit =)
Could you please try to test the same setup using directly node-pg?

@dmitryame
Copy link
Author

dmitryame commented Apr 18, 2024 via email

@MatteoGioioso
Copy link
Owner

MatteoGioioso commented Apr 22, 2024

There should be not much to do, this library is a wrapper around node-pg, it uses pretty much the same API except for .clean().

https://node-postgres.com/apis/client#new-client

const pg = require('pg')
const { Client } = pg

const client = new Client({
  host: 'my.database-server.com',
  port: 5334,
  database: 'database-name',
  user: 'database-user',
  password: 'secretpassword!!',
});

const handler = async (event, context) => {
  await client.connect();
  const result = await client.query(`SELECT 1+1 AS result`);
 // await client.clean(); COMMENT this out
  return {
    body: JSON.stringify({ message: result.rows[0] }),
    statusCode: 200
  }
}

There is also an ongoing issue that I found: brianc/node-postgres#2558

t4t5 added a commit to t4t5/microblame that referenced this issue Jun 8, 2024
It seems like there's a bug with the node-postgres library when running in Node 20 that leads to SSL errors:

MatteoGioioso/serverless-pg#91

Node 18 seems to always work fine though 👍
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants